Class: Opod::MemoryCache
- Inherits:
-
Object
- Object
- Opod::MemoryCache
- Defined in:
- lib/opod/memory.rb
Overview
A cache backed in memory. – This implementation is also the base for the Drb Cache. ++
Direct Known Subclasses
Instance Attribute Summary collapse
-
#hash ⇒ Object
readonly
Returns the value of attribute hash.
Instance Method Summary collapse
-
#all ⇒ Object
(also: #values)
Return all objects in the cache.
-
#delete(key, options = nil) ⇒ Object
(also: #remove)
Delete an object from the cache.
- #delete_if(&block) ⇒ Object
-
#gc! ⇒ Object
Perform session garbage collection.
-
#get(key, options = nil) ⇒ Object
(also: #read, #[])
Get an object from the cache.
-
#initialize(options = {}) ⇒ MemoryCache
constructor
A new instance of MemoryCache.
-
#keys ⇒ Object
Return all keys in the cache.
-
#mapping ⇒ Object
Return the mapping.
-
#set(key, value = nil, options = nil) ⇒ Object
(also: #put, #write, #[]=)
Put an object in the cache.
-
#update(hash) ⇒ Object
Was orig.
Constructor Details
#initialize(options = {}) ⇒ MemoryCache
Returns a new instance of MemoryCache.
13 14 15 16 17 18 19 |
# File 'lib/opod/memory.rb', line 13 def initialize( = {}) if [:sync] @hash = SyncHash else @hash = {} end end |
Instance Attribute Details
#hash ⇒ Object (readonly)
Returns the value of attribute hash.
11 12 13 |
# File 'lib/opod/memory.rb', line 11 def hash @hash end |
Instance Method Details
#all ⇒ Object Also known as: values
Return all objects in the cache.
76 77 78 |
# File 'lib/opod/memory.rb', line 76 def all @hash.values end |
#delete(key, options = nil) ⇒ Object Also known as: remove
Delete an object from the cache.
46 47 48 |
# File 'lib/opod/memory.rb', line 46 def delete(key, = nil) @hash.delete(key) end |
#delete_if(&block) ⇒ Object
51 52 53 |
# File 'lib/opod/memory.rb', line 51 def delete_if(&block) @hash.delete_if(&block) end |
#gc! ⇒ Object
Perform session garbage collection. Typically this method is called from a cron like mechanism.
58 59 60 |
# File 'lib/opod/memory.rb', line 58 def gc! delete_if { |key, s| s.expired? } end |
#get(key, options = nil) ⇒ Object Also known as: read, []
Get an object from the cache.
29 30 31 |
# File 'lib/opod/memory.rb', line 29 def get(key, = nil) @hash[key] end |
#keys ⇒ Object
Return all keys in the cache.
70 71 72 |
# File 'lib/opod/memory.rb', line 70 def keys @hash.keys end |
#mapping ⇒ Object
Return the mapping.
64 65 66 |
# File 'lib/opod/memory.rb', line 64 def mapping @hash end |
#set(key, value = nil, options = nil) ⇒ Object Also known as: put, write, []=
Put an object in the cache.
37 38 39 |
# File 'lib/opod/memory.rb', line 37 def set(key, value = nil, = nil) @hash[key] = value end |
#update(hash) ⇒ Object
Was orig. in Cache.
23 24 25 |
# File 'lib/opod/memory.rb', line 23 def update(hash) hash.each { |key, value| self[key] = value } end |