Class: TimedCache::FileStore
Overview
:nodoc:
Instance Method Summary collapse
- #get(key, timeout = @timed_cache.default_timeout, &block) ⇒ Object
-
#initialize(*args) ⇒ FileStore
constructor
A new instance of FileStore.
- #put(key, value, timeout) ⇒ Object
Constructor Details
#initialize(*args) ⇒ FileStore
Returns a new instance of FileStore.
177 178 179 180 181 182 183 184 |
# File 'lib/timedcache.rb', line 177 def initialize(*args) super(*args) filename = @options[:filename] unless filename raise ArgumentError, ":filename option must be specified for :file type store." end @cache = PStore.new(filename) end |
Instance Method Details
#get(key, timeout = @timed_cache.default_timeout, &block) ⇒ Object
194 195 196 197 198 199 200 |
# File 'lib/timedcache.rb', line 194 def get(key, timeout = @timed_cache.default_timeout, &block) if block generic_get(key, timeout, block, lambda {|k| @cache.transaction { @cache[key] } }) else @cache.transaction { generic_get(key, timeout, block) } end end |
#put(key, value, timeout) ⇒ Object
186 187 188 189 190 191 192 |
# File 'lib/timedcache.rb', line 186 def put(key, value, timeout) @cache.transaction { @cache[key] = ObjectContainer.new(value, timeout) } # Return just the given value, so that references to the # ObjectStore instance can't be held outside this TimedCache: value end |