Module: JSONCache

Extended by:
JSONCache
Included in:
JSONCache
Defined in:
lib/jsoncache.rb

Overview

JSONCache is a simple interface to cache JSON based API calls

Instance Method Summary collapse

Instance Method Details

#cache(key, options = {}) ⇒ Object

Retrieves cached data for the specified key and caches the data provided if the cache isn’t valid. Accepted options parameters

> [Boolean] symbolize

> [String] cache_directory

> [Fixnum] delta

Parameters:

  • key (String)

    The key in which to check for cached data.

  • options (Hash) (defaults to: {})

    A hash of the parameters to use when caching.



15
16
17
18
19
20
# File 'lib/jsoncache.rb', line 15

def cache(key, options = {})
  return retrieve_cache(key, options) if cached?(key, options)
  result = yield
  cache_file(key, result, options)
  result
end