The module provides the Drupal cache class that can be used instead of database cache.
That can be useful to store big permanent caches outside of Drupal database to keep the DB small.

How to use it?

Given the module installed to the site and ElasticSearch installed you need to configure the module. There are two ways to do it.

1. Using admin panel

Step 1. Download and enable variable module. Then set the index name and path to ElasticSearch installation on Administration » Configuration » System » Variables » ElasticSearch Cache.

Step 2. Switch the existing cache bins to the ElasticSearch Cache by updating settings.php. Simply add lines like $conf['cache_class_BIN'] = 'ElasticSearchCache'; where BIN is the name of the cache bin, e.g. cache_page.

2. Using Drush

Step 1. Set the index name and path to ElasticSearch installation by running commands:

drush vset elasticsearch_cache_index INDEX
drush vset elasticsearch_cache_path PATH

where INDEX and PATH are index name (if not set elasticsearch_cache_index name is used) and path to ElasticSearch installation (if not set http://localhost:9200 path is used) respectively.

Step 2. Switch the existing cache bins to the ElasticSearch Cache by running these commands:

drush vset cache_class_BIN ElasticSearchCache

where BIN is the name of the cache bin.

Hidden Configurations

There are few extra configurations that you may adjust by setting the variables like in Steps 2 above.
1. elasticsearch_cache__INDEX__bootstrapped: if not set to TRUE the index will be automatically created in you ElasticSearch installation with the default settings of 2 shards and 0 replicas.
2. elasticsearch_cache_index__BIN: the variable allows overriding the index name for some bins.
3. elasticsearch_cache_readonly__bin__BIN, elasticsearch_cache_readonly__index__INDEX and elasticsearch_cache_readonly: the variables are used to put cache bins to readonly state. The first value available is used, if none are available bin is considered NOT readonly. In some cases you may want to prevent the site from writing more caches into ElasticSearch and use existing records only.
4. elasticsearch_cache_path__bin__BIN and elasticsearch_cache_path__index__INDEX: these variables are used to override the path to the defaule ElasticSearch installation from elasticsearch_cache_path variable.

Caveats

1. ElasticSearch access may be slow compared to database but it is good for storing big permanent caches somewhere outside of the database to prevent if from growing enormously.
It works best for storing "cold' caches of the external API's responses that have usage quotas and don't update frequently.
2. Expired caches are automatically removed with the cron runs: 100 items from every ElatsicSearch-driven bin.

Credits

Development of the initial version of the module was supported by Daily Meal Ventures

Project information

Releases