Class: Card::Cache::Persistent
Instance Attribute Summary collapse
-
#prefix ⇒ Object
readonly
Returns the value of attribute prefix.
Instance Method Summary collapse
- #delete(key) ⇒ Object
- #exist?(key) ⇒ Boolean
- #fetch(key, &block) ⇒ Object
- #full_key(key) ⇒ Object
-
#initialize(opts) ⇒ Persistent
constructor
A new instance of Persistent.
- #read(key) ⇒ Object
- #reset ⇒ Object
- #system_prefix=(system_prefix) ⇒ Object
- #write(key, value) ⇒ Object
- #write_variable(key, variable, value) ⇒ Object
Constructor Details
#initialize(opts) ⇒ Persistent
Returns a new instance of Persistent.
6 7 8 9 10 |
# File 'lib/card/cache/persistent.rb', line 6 def initialize opts @store = opts[:store] self.system_prefix = opts[:prefix] || Card::Cache.system_prefix(opts[:class]) end |
Instance Attribute Details
#prefix ⇒ Object (readonly)
Returns the value of attribute prefix.
4 5 6 |
# File 'lib/card/cache/persistent.rb', line 4 def prefix @prefix end |
Instance Method Details
#delete(key) ⇒ Object
37 38 39 |
# File 'lib/card/cache/persistent.rb', line 37 def delete key @store.delete full_key(key) end |
#exist?(key) ⇒ Boolean
47 48 49 |
# File 'lib/card/cache/persistent.rb', line 47 def exist? key @store.exist? full_key(key) end |
#fetch(key, &block) ⇒ Object
33 34 35 |
# File 'lib/card/cache/persistent.rb', line 33 def fetch key, &block @store.fetch full_key(key), &block end |
#full_key(key) ⇒ Object
51 52 53 |
# File 'lib/card/cache/persistent.rb', line 51 def full_key key @prefix + key end |
#read(key) ⇒ Object
17 18 19 |
# File 'lib/card/cache/persistent.rb', line 17 def read key @store.read(full_key(key)) end |
#reset ⇒ Object
41 42 43 44 45 |
# File 'lib/card/cache/persistent.rb', line 41 def reset @store.clear rescue => e Rails.logger.debug "Problem clearing cache: #{e.}" end |
#system_prefix=(system_prefix) ⇒ Object
12 13 14 15 |
# File 'lib/card/cache/persistent.rb', line 12 def system_prefix= system_prefix @system_prefix = system_prefix @prefix = "#{system_prefix}/" end |
#write(key, value) ⇒ Object
29 30 31 |
# File 'lib/card/cache/persistent.rb', line 29 def write key, value @store.write(full_key(key), value) end |
#write_variable(key, variable, value) ⇒ Object
21 22 23 24 25 26 27 |
# File 'lib/card/cache/persistent.rb', line 21 def write_variable key, variable, value if @store && (object = @store.read key) object.instance_variable_set "@#{variable}", value @store.write key, object end value end |