Class: Dragonfly::SimpleCache
- Defined in:
- lib/dragonfly/simple_cache.rb
Instance Attribute Summary collapse
-
#max_size ⇒ Object
readonly
Returns the value of attribute max_size.
Instance Method Summary collapse
- #[]=(key, value) ⇒ Object
-
#initialize(max_size) ⇒ SimpleCache
constructor
A new instance of SimpleCache.
Constructor Details
#initialize(max_size) ⇒ SimpleCache
Returns a new instance of SimpleCache.
4 5 6 7 |
# File 'lib/dragonfly/simple_cache.rb', line 4 def initialize(max_size) @max_size = max_size @keys = [] end |
Instance Attribute Details
#max_size ⇒ Object (readonly)
Returns the value of attribute max_size
9 10 11 |
# File 'lib/dragonfly/simple_cache.rb', line 9 def max_size @max_size end |
Instance Method Details
#[]=(key, value) ⇒ Object
11 12 13 14 15 16 17 18 19 20 |
# File 'lib/dragonfly/simple_cache.rb', line 11 def []=(key, value) if !has_key?(key) @keys << key if size == max_size key_to_purge = @keys.shift delete(key_to_purge) end end super end |