Module: FileCache
- Defined in:
- lib/file_cache.rb
Overview
FileCache
FileCache is a simple utility to persist arbitrary data into a file. Just wrap the action you want to cache into a FileCache call and it will be available for 30 minutes by default.
FileCache uses the default tmp-directory of your OS, but you may override that setting via file_cache_dir
Example
require 'file_cache'
include FileCache
file_cache :cache_token_name do
#some_stuff_that_should_be_cached_executed_here
end
Instance Attribute Summary collapse
-
#file_cache_dir ⇒ Object
writeonly
configures the directory where file_cache persists the payload.
Instance Method Summary collapse
-
#file_cache(token, caching_time_in_minutes = 30, &payload) ⇒ Object
performs the caching with the name of
token
for the givenpayload
block.
Instance Attribute Details
#file_cache_dir=(value) ⇒ Object
configures the directory where file_cache persists the payload
21 22 23 |
# File 'lib/file_cache.rb', line 21 def file_cache_dir=(value) @file_cache_dir = value end |
Instance Method Details
#file_cache(token, caching_time_in_minutes = 30, &payload) ⇒ Object
performs the caching with the name of token
for the given payload
block
the caching_time_in_minutes
defaults to half an hour
26 27 28 29 30 31 32 33 |
# File 'lib/file_cache.rb', line 26 def file_cache(token, caching_time_in_minutes=30, &payload) file = file_cache_name(token) if not_cached_or_to_old? file, caching_time_in_minutes load_from_file_cache file else write_to_file_cache file, (yield payload) end end |