Module: Workarea::Elasticsearch::QueryCache

Defined in:
lib/workarea/elasticsearch/query_cache.rb

Defined Under Namespace

Modules: Client Classes: Middleware

Class Method Summary collapse

Class Method Details

.cacheObject

Execute the block while using the query cache.

Examples:

Execute with the cache.

QueryCache.cache { collection.find }


53
54
55
56
57
58
59
# File 'lib/workarea/elasticsearch/query_cache.rb', line 53

def cache
  enabled = QueryCache.enabled?
  QueryCache.enabled = true
  yield
ensure
  QueryCache.enabled = enabled
end

.cache_tableHash

Get the cached queries.

Examples:

Get the cached queries from the current thread.

QueryCache.cache_table


13
14
15
# File 'lib/workarea/elasticsearch/query_cache.rb', line 13

def cache_table
  self.query_cache ||= {}
end

.clear_cachenil

Clear the query cache.

Examples:

Clear the cache.

QueryCache.clear_cache


23
24
25
# File 'lib/workarea/elasticsearch/query_cache.rb', line 23

def clear_cache
  self.query_cache = nil
end

.enabled=(value) ⇒ Object

Set whether the cache is enabled.

Examples:

Set if the cache is enabled.

QueryCache.enabled = true


33
34
35
# File 'lib/workarea/elasticsearch/query_cache.rb', line 33

def enabled=(value)
  self.query_cache_enabled = value
end

.enabled?true, false

Is the query cache enabled on the current thread?

Examples:

Is the query cache enabled?

QueryCache.enabled?


43
44
45
# File 'lib/workarea/elasticsearch/query_cache.rb', line 43

def enabled?
  !!self.query_cache_enabled
end

.uncachedObject

Execute the block with the query cache disabled.

Examples:

Execute without the cache.

QueryCache.uncached { collection.find }


67
68
69
70
71
72
73
# File 'lib/workarea/elasticsearch/query_cache.rb', line 67

def uncached
  enabled = QueryCache.enabled?
  QueryCache.enabled = false
  yield
ensure
  QueryCache.enabled = enabled
end