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

Inherits:
ActiveSupport::Cache::Store show all
Defined in:
activesupport/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, #fetch_multi, #increment, #mute, #read, #read_multi, #silence!, #write, #write_multi

Constructor Details

#initializeLocalStore

Returns a new instance of LocalStore.



39
40
41
42
# File 'activesupport/lib/active_support/cache/strategy/local_cache.rb', line 39

def initialize
  super
  @data = {}
end

Instance Method Details

#clear(options = nil) ⇒ Object



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

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

#delete_entry(key, options) ⇒ Object



62
63
64
# File 'activesupport/lib/active_support/cache/strategy/local_cache.rb', line 62

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

#fetch_entry(key, options = nil) ⇒ Object

:nodoc:



66
67
68
# File 'activesupport/lib/active_support/cache/strategy/local_cache.rb', line 66

def fetch_entry(key, options = nil) # :nodoc:
  @data.fetch(key) { @data[key] = yield }
end

#read_entry(key, options) ⇒ Object



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

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

#synchronizeObject

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



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

def synchronize # :nodoc:
  yield
end

#write_entry(key, value, options) ⇒ Object



57
58
59
60
# File 'activesupport/lib/active_support/cache/strategy/local_cache.rb', line 57

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