Cache
Adding a cache to OKA can greatly improve the user experience. With a cache backend, OKA will keep the results of the requests in the cache and serve them more quickly when requested. Some analysis require longer computations than others and leverage the caching mechanism. This is especially useful if you access the same page of OKA regularly.
By default OKA will use its database to automatically cache the requests.
However, you also have the possibility to configure a Memcached based solution to cache requests if you want it.
You can define which caching backend you want to use with OKA by setting the main_cache variable in the ${OKA_INSTALL_DIR}/config/oka/oka.yaml file.
Main cache
There are 3 backend possibilities to consider. The default DatabaseCache mechanism and two Memcached based options which are entirely memory-based cache server.
Regarding Memcached, it runs as a daemon and is allotted a specified amount of RAM. All it does is provide a fast interface for adding, retrieving and deleting
data in the cache. All data is stored directly in memory, so there’s no overhead of database or filesystem usage.
DatabaseCache
DatabaseCache is a caching backend that stores cache data in your database.
During installation, the necessary cache table is created automatically, and the configuration is set up.
The main_cache variable must be set as follows in the ${OKA_INSTALL_DIR}/config/oka/oka.yaml file:
main_cache:
backend: django.core.cache.backends.db.DatabaseCache
location: oka_cache_table
If you need more details on how to configure DatabaseCache, you can refer to the official Django documentation.
MemcachedCache
Memcached is a free and open source, high-performance, distributed memory object caching system.
To use Memcached, you must install memcached & libmemcached-tools libraries:
sudo apt install memcached libmemcached-tools
The main_cache variable must be set as follows in the ${OKA_INSTALL_DIR}/config/oka/oka.yaml file:
main_cache:
backend: django.core.cache.backends.memcached.PyMemcacheCache
location: 127.0.0.1:11211
Of course, if Memcached is installed in a separate server, you will need to adapt the IP and port in the location section accordingly (here 127.0.0.1:11211).
More details on how to configure Memcached, and especially how much RAM it can use can be found here.
Fallback cache
When the main cache is not available or returns an error, OKA switches to a fallback cache.
OKA is configured with a “dummy cache” as a fallback cache, meaning that there is no caching and the request will be sent to the API to get the response.