Class: LRU

Inherits:
Hash
  • Object
show all
Defined in:
lib/rabl/cache_engine.rb

Overview

Defines the default cache engine for RABL when caching is invoked for a template. You can define your own caching engines by creating an object that responds to fetch and setting the configuration option:

config.cache_engine = AdvancedCacheEngine.new

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeLRU

Returns a new instance of LRU.



11
12
13
14
# File 'lib/rabl/cache_engine.rb', line 11

def initialize
  super
  self.max_size = 100_000
end

Instance Attribute Details

#max_sizeObject

Returns the value of attribute max_size.



9
10
11
# File 'lib/rabl/cache_engine.rb', line 9

def max_size
  @max_size
end

Instance Method Details

#[]=(k, v) ⇒ Object



16
17
18
19
20
# File 'lib/rabl/cache_engine.rb', line 16

def []= k,v
  r = super
  limit_size
  r
end

#limit_sizeObject



22
23
24
25
26
# File 'lib/rabl/cache_engine.rb', line 22

def limit_size
  if size > max_size then
    delete keys.shift while size > max_size
  end
end