A cache backed in memory.
Methods
Attributes
| [R] | hash |
Public Class methods
[ show source ]
# File lib/glue/cache/memory.rb, line 15
15: def initialize(options = {})
16: if options[:sync]
17: @hash = SyncHash
18: else
19: @hash = {}
20: end
21: end
Public Instance methods
Alias for #get
Alias for #set
Return all objects in the cache.
This method is also aliased as
values
[ show source ]
# File lib/glue/cache/memory.rb, line 72
72: def all
73: @hash.values
74: end
Delete an object from the cache.
This method is also aliased as
remove
[ show source ]
# File lib/glue/cache/memory.rb, line 42
42: def delete(key, options = nil)
43: @hash.delete(key)
44: end
[ show source ]
# File lib/glue/cache/memory.rb, line 47
47: def delete_if(&block)
48: @hash.delete_if(&block)
49: end
Perform session garbage collection. Typically this method is called from a cron like mechanism.
[ show source ]
# File lib/glue/cache/memory.rb, line 54
54: def gc!
55: delete_if { |key, s| s.expired? }
56: end
Get an object from the cache.
[ show source ]
# File lib/glue/cache/memory.rb, line 25
25: def get(key, options = nil)
26: @hash[key]
27: end
Return all keys in the cache.
[ show source ]
# File lib/glue/cache/memory.rb, line 66
66: def keys
67: @hash.keys
68: end
Return the mapping.
[ show source ]
# File lib/glue/cache/memory.rb, line 60
60: def mapping
61: @hash
62: end
Alias for #set
Alias for #get
Alias for #delete
Put an object in the cache.
[ show source ]
# File lib/glue/cache/memory.rb, line 33
33: def set(key, value = nil, options = nil)
34: @hash[key] = value
35: end
Alias for #all
Alias for #set