Class: Wovnrb::MemoryCache
Constant Summary
collapse
- @@default_memory_cache_config =
{
cache_megabytes: 200,
ttl_seconds: 300
}
Instance Method Summary
collapse
Methods inherited from CacheBase
build, get_single, reset_cache, set_single
Constructor Details
Returns a new instance of MemoryCache.
12
13
14
15
16
17
|
# File 'lib/wovnrb/text_caches/memory_cache.rb', line 12
def initialize(config)
@config = merge_setting(@@default_memory_cache_config, config)
cache_size = @config[:cache_megabytes].to_f
ttl = @config[:ttl_seconds].to_i
@cache_store = ActiveSupport::Cache::MemoryStore.new(expires_in: ttl.seconds, size: cache_size.megabytes)
end
|
Instance Method Details
#get(key) ⇒ Object
23
24
25
26
|
# File 'lib/wovnrb/text_caches/memory_cache.rb', line 23
def get(key)
stored_value =@cache_store.fetch(key)
decompress(stored_value) if stored_value
end
|
#options ⇒ Object
28
29
30
|
# File 'lib/wovnrb/text_caches/memory_cache.rb', line 28
def options
@cache_store.options.clone
end
|
#put(key, value) ⇒ Object
19
20
21
|
# File 'lib/wovnrb/text_caches/memory_cache.rb', line 19
def put(key, value)
@cache_store.write(key, compress(value))
end
|