Class: ActiveSupport::Cache::Strategy::LocalCache::LocalStore

Inherits:
ActiveSupport::Cache::Store show all
Defined in:
lib/active_support/cache/strategy/local_cache.rb

Overview

Simple memory backed cache. This cache is not thread safe and is intended only for serving as a temporary memory cache for a single thread.

Instance Attribute Summary

Attributes inherited from ActiveSupport::Cache::Store

#options, #silence

Instance Method Summary collapse

Methods inherited from ActiveSupport::Cache::Store

#cleanup, #decrement, #delete, #delete_matched, #exist?, #fetch, #increment, instrument, instrument=, #mute, #read, #read_multi, #silence!, #write

Constructor Details

#initializeLocalStore

Returns a new instance of LocalStore.



31
32
33
34
# File 'lib/active_support/cache/strategy/local_cache.rb', line 31

def initialize
  super
  @data = {}
end

Instance Method Details

#clear(options = nil) ⇒ Object



41
42
43
# File 'lib/active_support/cache/strategy/local_cache.rb', line 41

def clear(options = nil)
  @data.clear
end

#delete_entry(key, options) ⇒ Object



54
55
56
# File 'lib/active_support/cache/strategy/local_cache.rb', line 54

def delete_entry(key, options)
  !!@data.delete(key)
end

#read_entry(key, options) ⇒ Object



45
46
47
# File 'lib/active_support/cache/strategy/local_cache.rb', line 45

def read_entry(key, options)
  @data[key]
end

#synchronizeObject

Don’t allow synchronizing since it isn’t thread safe,



37
38
39
# File 'lib/active_support/cache/strategy/local_cache.rb', line 37

def synchronize # :nodoc:
  yield
end

#write_entry(key, value, options) ⇒ Object



49
50
51
52
# File 'lib/active_support/cache/strategy/local_cache.rb', line 49

def write_entry(key, value, options)
  @data[key] = value
  true
end