Redis is an in-memory data store, often used to implement caching strategies. Using a Redis cache with TRAX LRS can speed-up some requests and remove pressure on your primary database.
A typical scenario is an LRS with a very few number of clients performing long series of small requests.
As the APIs are stateless, the LRS has to check the clients credentials for each request, again and again. This may have a cost it terms of writing performances.
When the Redis cache is enabled, TRAX LRS caches clients data in order to speed-up credentials checking.
There are a number of situations where TRAX LRS needs to access activities, agents and verbs data to perform some queries.
Unlike statements, the number of agents, verbs and activities (in a lesser extent) in quite limited in most of the LRS projects.
When the Redis cache is enabled, TRAX LRS caches activities, agents and verbs data to get them faster and limit the pressure on the main database.
php.ini
..env
file if needed. The following example shows the default value for each setting.REDIS_HOST=127.0.0.1
REDIS_PORT=6379
REDIS_PASSWORD=
REDIS_CACHE_DB=1
Finally, enable the Redis cache in your .env
file.
CACHE_DRIVER=redis
You can open http://your-traxlrs-root-url/test/redis
to check that your Redis cache is up and running.
Clients data is cached for 30 seconds and this is not configurable. Be aware that when you change the credentials of a client, it may take effect in 30 seconds.
Activities, agents and verbs data is cached with an unlimited duration by default. However, you can set a duration (in seconds) if it makes sense for your project.
XAPI_CACHE_DURATION=10000
The cache is automatically and progressively filled when the LRS records new statements. However, this may be usefull to build or rebuild the cache in some situations, including:
You can rebuild the cache with the following commands, for each store separately.
php artisan agents:cache
php artisan verbs:cache
php artisan activities:cache
Option | Example of value | Description |
---|---|---|
--owner | 1 |
Internal ID of the LRS store |
If for any reason you need to flush the cache, you can use:
php artisan cache:clear