Class: Geogov::SimpleCache
- Inherits:
-
Object
- Object
- Geogov::SimpleCache
- Defined in:
- lib/geogov/utils.rb
Instance Method Summary collapse
-
#initialize(delegate) ⇒ SimpleCache
constructor
A new instance of SimpleCache.
- #method_missing(m, *args) ⇒ Object
Constructor Details
#initialize(delegate) ⇒ SimpleCache
Returns a new instance of SimpleCache.
68 69 70 71 |
# File 'lib/geogov/utils.rb', line 68 def initialize(delegate) @delegate = delegate @cache = LruCache.new(1000) end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(m, *args) ⇒ Object
73 74 75 76 77 78 79 80 81 82 83 |
# File 'lib/geogov/utils.rb', line 73 def method_missing(m, *args) arg_key = args.inspect cache_key = "#{m}--#{arg_key}" if @cache[cache_key] return @cache[cache_key] else result = @delegate.send(m,*args) @cache[cache_key] = result return result end end |