Class: Dragonfly::SimpleCache
Instance Attribute Summary (collapse)
-
- (Object) max_size
readonly
Returns the value of attribute max_size.
Instance Method Summary (collapse)
- - (Object) []=(key, value)
-
- (SimpleCache) initialize(max_size)
constructor
A new instance of SimpleCache.
Methods inherited from Hash
Constructor Details
- (SimpleCache) initialize(max_size)
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
- (Object) max_size (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
- (Object) []=(key, value)
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 |