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 cache the requests using local-memory caching. This cache is per-process and thread-safe. However, we recommend the deployment of a Memcached-based solution to cache requests. 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 2 backend possibilities based on Memcached which is an entirely memory-based cache server. Memcached 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. Memcached is, by default, a Least Recently Used cache. Items expire after a specified amount of time.

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.