Class: Opod::OgCache
- Inherits:
-
Object
- Object
- Opod::OgCache
- Defined in:
- lib/opod/og.rb
Instance Method Summary collapse
- #[](k) ⇒ Object
- #[]=(k, v) ⇒ Object
- #all ⇒ Object
- #gc! ⇒ Object
-
#initialize(cache_name, keepalive = nil) ⇒ OgCache
constructor
A new instance of OgCache.
Constructor Details
#initialize(cache_name, keepalive = nil) ⇒ OgCache
Returns a new instance of OgCache.
19 20 21 22 |
# File 'lib/opod/og.rb', line 19 def initialize(cache_name, keepalive = nil) @cache_name = cache_name @keepalive = keepalive end |
Instance Method Details
#[](k) ⇒ Object
36 37 38 39 |
# File 'lib/opod/og.rb', line 36 def [](k) s = OgCached.find_by_unique_id_and_cache_name(k.to_s, @cache_name) decode(s.content) if s end |
#[]=(k, v) ⇒ Object
24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/opod/og.rb', line 24 def []=(k,v) unless s = OgCached.find_by_unique_id_and_cache_name(k.to_s, @cache_name) s = OgCached.new s.cache_name = @cache_name s.expires = Time.now + @keepalive if @keepalive s.unique_id = k.to_s end #s.content = v.to_yaml s.content = encode(v) s.insert end |
#all ⇒ Object
45 46 47 |
# File 'lib/opod/og.rb', line 45 def all OgCached.find_by_cache_name(@cache_name) end |
#gc! ⇒ Object
41 42 43 |
# File 'lib/opod/og.rb', line 41 def gc! OgCached.find(:condition => ["expires < ? AND cache_name = ?", Time.now, @cache_name]).each {|s| s.delete } end |