Class: ActiveSupport::Cache::ElasticsearchStore
- Inherits:
-
Store
- Object
- Store
- ActiveSupport::Cache::ElasticsearchStore
- Defined in:
- lib/activesupport/cache/elasticsearch_store.rb
Overview
A cache store implementation which stores data in ElasticSearch: www.elasticsearch.org/
This store is experimental and was developed against a non-clustered ElasticSearch environment.
Instance Method Summary collapse
-
#clear(_options = nil) ⇒ Object
Clear the entire cache in our Elasticsearch index.
-
#initialize(*addresses) ⇒ ElasticsearchStore
constructor
Creates a new ElasticstoreSearch object, with the given elasticsearch server addresses.
Constructor Details
#initialize(*addresses) ⇒ ElasticsearchStore
Creates a new ElasticstoreSearch object, with the given elasticsearch server addresses. The addresses and the randomize_hosts, retry_on_failure and reload_connections options are passed verbatim to Elasticsearch::Client.new.
Defaults to ‘localhost:9200’ if no addresses are specified.
Will create an index named ‘cache’ unless the :index_name option is specified.
35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 |
# File 'lib/activesupport/cache/elasticsearch_store.rb', line 35 def initialize(*addresses) addresses = addresses.flatten = addresses. = .extract!(:retry_on_failure, :randomize_hosts, :reload_connections) .delete_if { |k, v| v.nil? } @index_name = .delete(:index_name) || 'cache' if [:namespace] raise ArgumentError, ":namespace option not yet supported" end super() addresses = %w(localhost:9200) if addresses.length == 0 [:addresses] = addresses @client = Elasticsearch::Client.new() @index_created = false end |
Instance Method Details
#clear(_options = nil) ⇒ Object
Clear the entire cache in our Elasticsearch index. This method should be used with care when shared cache is being used.
58 59 60 61 |
# File 'lib/activesupport/cache/elasticsearch_store.rb', line 58 def clear( = nil) # TODO: Support namespaces @client.delete_by_query index: @index_name, type: 'entry', body: { query: { match_all: {} } } end |