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}/conf/oka.conf 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}/conf/oka.conf 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

Then MAIN_CACHE variable must be set as follow in the ${OKA_INSTALL_DIR}/conf/oka.conf 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.

ElastiCache

ElastiCache for Memcached is a fully managed Memcached service provided by AWS (Amazon Web Services).

You must first create an ElastiCache for Memcached cluster on AWS. Its configuration is out of the scope of this documentation, and we refer you to the Getting Started documentation. Make sure that the server/instance on which OKA is setup can reache the ElastiCache for Memcached cluster, watch out especially for the Security Group’s rules (inbound & outbound).

Once your ElastiCache for Memcached cluster is up and running, retrieve its Configuration Endpoint, and set the MAIN_CACHE variable to (replace oka-cache.u5ihxl.cfg.euw1.cache.amazonaws.com:11211 by your Configuration Endpoint:

MAIN_CACHE={"BACKEND":"django_elasticache.memcached.ElastiCache","LOCATION":"oka-cache.u5ihxl.cfg.euw1.cache.amazonaws.com:11211"}

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.