Skip to content

233. Foretify Caching

Foretify supports caching for:

  • Map data
  • Compiler output
  • Static Analysis output

Foretify caching is version-based — data cached by one Foretify version cannot be used by another version.

233.1 Configuration file

Foretellix recommends configuring caching through a configuration file.

By default, Foretify uses ~/.foretify.cfg.

To use a different configuration file, set the FTX_CONFIGPATH environment variable to the required path.

Shell command: set configuration file path
export FTX_CONFIGPATH=/path/to/foretify.cfg

233.2 Selecting the cache backend

The cache_backend_type setting determines which caching backend Foretify uses.

Supported backends:

  • filesystem — shared filesystem
  • redis — Redis server
  • none — disable caching

233.3 Shared filesystem configuration

To configure the shared filesystem as the cache backend, set the foretify_cache_directory setting to the root cache directory.

This directory must:

  • Be accessible to all Foretify instances.
  • Have full read and write permissions for the user running Foretify.

Configuration example:

~/.foretify.cfg
# Foretify Cache configuration
foretify_cache:
  cache_backend_type: filesystem

  filesystem:
    foretify_cache_directory: /data/foretify_cache

233.4 Redis configuration

To use Redis as the cache backend, configure the redis section under foretify_cache.

233.4.1 Required Redis settings

  • redis_host — IP address or hostname of the Redis server
  • redis_port — Port on which the Redis server is accessible

233.4.2 Optional Redis settings

  • redis_username — Username, if Redis authentication requires it
  • redis_password — Password, if Redis is password protected
  • redis_database — Database index to use (default: 0)
  • redis_debug — Enable Redis debug logging

Configuration example:

~/.foretify.cfg
# Foretify Cache configuration
foretify_cache:
  cache_backend_type: redis

  redis:
    redis_host: 127.0.0.1           # required
    redis_port: 7777                # required (default: 6379)
    redis_username: myuser          # optional
    redis_password: P1gB45@ll@j     # optional
    redis_database: 1               # optional (default: 0)
    # redis_debug: true             # optional

Note

The Redis server must be accessible to all Foretify instances.

233.5 Setting up local Redis

Using a local Redis instance instead of the filesystem backend provides automatic memory management. Redis can be configured to automatically remove older data when memory limits are reached, whereas the filesystem backend requires periodic manual cleanup to prevent storage from growing indefinitely.

To set up local Redis:

  1. Install Redis locally using the official Redis documentation.

  2. Edit the Redis configuration file /etc/redis/redis.conf (requires root access).

    Configuration example:

    /etc/redis/redis.conf
    port 7777                          # Port for Redis to listen on (default: 6379)
    save ""                            # Disable dumping data to disk
    requirepass frtlx@1000@            # Password for database access
    # Automatic removal of old data:
    maxmemory-samples 10               
    maxmemory-policy allkeys-lru
    

    The maxmemory configuration specifies the maximum amount of memory to use for the cache data.

    • maxmemory-samples: Sets the number of keys Redis examines before deciding which ones to delete. Moving to 10 is the standard recommendation for production environments requiring high precision. See also Redis memory optimization.
    • maxmemory-policy: Sets the eviction policy to use when the limit set by maxmemory is reached.
      allkeys-lru specifies to evict the least recently used (LRU) keys. See also Redis eviction policy
  3. Save the configuration and restart Redis:

    Shell command: restart Redis
    sudo systemctl restart redis-server
    
  4. Validate the connection to the local server using the syntx:

    Shell command: connect to local Redis
    redis-cli -p <port> --pass <password>
    

    Configuration example:

    Shell command: connect to local Redis
    redis-cli -p 777 --pass frtlx@1000@
    

    A successful connection confirms the local Redis server is properly configured.