Module: JSONCache

Defined in:
lib/jsoncache.rb,
lib/jsoncache/filecache.rb

Overview

JSONCache is a simple interface to cache JSON based API calls

Author

Derek Stride ([email protected])

License

MIT

Defined Under Namespace

Modules: FileCache

Instance Method Summary collapse

Instance Method Details

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



8
9
10
11
12
13
14
15
16
17
# File 'lib/jsoncache.rb', line 8

def cache(method, options = {})
  original = "__uncached_#{method}__"
  ([Class, Module].include?(self.class) ? self : self.class).class_eval do
    alias_method original, method
    private original
    define_method(method) do |*args|
      JSONCache::FileCache.cache(*args, options) { send(original, *args) }
    end
  end
end