Class: Ramaze::Cache::LocalMemCache
- Inherits:
-
Object
- Object
- Ramaze::Cache::LocalMemCache
- Includes:
- Cache::API
- Defined in:
- lib/ramaze/cache/localmemcache.rb
Overview
Cache based on the localmemcache library which utilizes mmap to share strings in memory between ruby instances.
Constant Summary
- OPTIONS =
{ :size_mb => 1024, :serialize => true, :serializer => ::Marshal, # something that responds to ::load and ::dump }
Instance Method Summary (collapse)
-
- (Object) cache_clear
Wipe out all data in localmemcached, use with care.
-
- (Object) cache_delete(*args)
-
- (Object) cache_fetch(*args)
NOTE: * We have no way of knowing whether the value really is nil, we assume you wouldn't cache nil and return the default instead.
-
- (Object) cache_setup(host, user, app, name)
Connect to localmemcache.
-
- (Object) cache_store(*args)
Instance Method Details
- (Object) cache_clear
Wipe out all data in localmemcached, use with care.
30 31 32 |
# File 'lib/ramaze/cache/localmemcache.rb', line 30 def cache_clear @store.clear end |
- (Object) cache_delete(*args)
34 35 36 |
# File 'lib/ramaze/cache/localmemcache.rb', line 34 def cache_delete(*args) super { |key| @store.delete(key.to_s); nil } end |
- (Object) cache_fetch(*args)
NOTE: * We have no way of knowing whether the value really is nil, we assume you wouldn't cache nil and return the default instead.
41 42 43 44 45 46 |
# File 'lib/ramaze/cache/localmemcache.rb', line 41 def cache_fetch(*args) super { |key| value = @store[key.to_s] @serializer.load(value) if value } end |
- (Object) cache_setup(host, user, app, name)
Connect to localmemcache
20 21 22 23 24 25 26 27 |
# File 'lib/ramaze/cache/localmemcache.rb', line 20 def cache_setup(host, user, app, name) @namespace = [host, user, app, name].compact.join('-') = {:namespace => @namespace}.merge(OPTIONS) @serialize = .delete(:serialize) @serializer = .delete(:serializer) @store = ::LocalMemCache.new() end |
- (Object) cache_store(*args)
48 49 50 |
# File 'lib/ramaze/cache/localmemcache.rb', line 48 def cache_store(*args) super { |key, value| @store[key.to_s] = @serializer.dump(value) } end |