Class: GameFaqs::Caching::Store

Inherits:
Hash
  • Object
show all
Defined in:
lib/gamefaqs/caching.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(*args) ⇒ Store

Returns a new instance of Store.



6
7
8
9
# File 'lib/gamefaqs/caching.rb', line 6

def initialize(*args)
  super(*args)
  @keys = []
end

Instance Attribute Details

#keysObject (readonly)

Returns the value of attribute keys.



4
5
6
# File 'lib/gamefaqs/caching.rb', line 4

def keys
  @keys
end

Instance Method Details

#[]=(key, value) ⇒ Object



11
12
13
14
15
# File 'lib/gamefaqs/caching.rb', line 11

def []=(key, value)
  @keys << key
  clean!
  super
end

#clean!Object

retain only second half of cache if it gets to big



18
19
20
21
22
23
# File 'lib/gamefaqs/caching.rb', line 18

def clean!
  if @keys.size > Cache.max_size
    @keys = @keys[(Cache.max_size/2)...@keys.size]
    reject! { |key, value| !@keys.include?(key) }
  end
end