Class: Ramaze::Cache::LRU
- Inherits:
-
Object
- Object
- Ramaze::Cache::LRU
- Includes:
- Cache::API
- Defined in:
- lib/ramaze/cache/lru.rb
Overview
Cache class that uses LRUHash as a storage engine. This cache has the advantage that unlike Innate::Cache::Memory it does not leak memory over time when using the cache for sessions.
Constant Summary collapse
- OPTIONS =
Hash containing all the options for the cache.
{ # expiration in seconds :expiration => nil, # maximum elements in the cache :max_count => 10000, # maximum total memory usage of the cache :max_total => nil, # maximum memory usage of an element of the cache :max_value => nil, }
Instance Method Summary collapse
-
#cache_clear ⇒ Object
Clears the entire cache.
-
#cache_delete(*args) ⇒ Object
Deletes a set of data from the cache.
-
#cache_fetch(*args) ⇒ Object
Retrieves a set of data from the cache.
-
#cache_setup(host, user, app, name) ⇒ Object
Prepares the cache by creating a new instance of Ramaze::LRUHash using the options set in OPTIONS.
-
#cache_store(*args) ⇒ Object
Stores a set of data in the cache.
Instance Method Details
#cache_clear ⇒ Object
Clears the entire cache.
50 51 52 |
# File 'lib/ramaze/cache/lru.rb', line 50 def cache_clear @store.clear end |
#cache_delete(*args) ⇒ Object
Deletes a set of data from the cache
83 84 85 |
# File 'lib/ramaze/cache/lru.rb', line 83 def cache_delete(*args) super { |key| @store.delete(key) } end |
#cache_fetch(*args) ⇒ Object
Retrieves a set of data from the cache.
72 73 74 |
# File 'lib/ramaze/cache/lru.rb', line 72 def cache_fetch(*args) super { |key| @store[key] } end |
#cache_setup(host, user, app, name) ⇒ Object
Prepares the cache by creating a new instance of Ramaze::LRUHash using the options set in OPTIONS.
40 41 42 |
# File 'lib/ramaze/cache/lru.rb', line 40 def cache_setup(host, user, app, name) @store = Ramaze::LRUHash.new(OPTIONS) end |
#cache_store(*args) ⇒ Object
Stores a set of data in the cache.
61 62 63 |
# File 'lib/ramaze/cache/lru.rb', line 61 def cache_store(*args) super { |key, value| @store[key] = value } end |