Class: APICache::AbstractStore

Inherits:
Object
  • Object
show all
Defined in:
lib/api_cache/abstract_store.rb

Direct Known Subclasses

DalliStore, MemoryStore, MonetaStore, NullStore

Instance Method Summary collapse

Constructor Details

#initializeAbstractStore



3
4
5
# File 'lib/api_cache/abstract_store.rb', line 3

def initialize
  raise "Method not implemented. Called abstract class."
end

Instance Method Details

#created_at(key) ⇒ Object

created_at returns the time when the key was last set



28
29
30
# File 'lib/api_cache/abstract_store.rb', line 28

def created_at(key)
  raise "Method not implemented. Called abstract class."
end

#delete(key) ⇒ Object

Delete the given key. The return value is not used.



18
19
20
# File 'lib/api_cache/abstract_store.rb', line 18

def delete(key)
  raise "Method not implemented. Called abstract class."
end

#exists?(key) ⇒ Boolean

Does a given key exist in the cache?



23
24
25
# File 'lib/api_cache/abstract_store.rb', line 23

def exists?(key)
  raise "Method not implemented. Called abstract class."
end

#expired?(key, timeout) ⇒ Boolean

expired? returns true if the given timeout has passed since the key was set. It has nothing to say about the existence or otherwise of said key.



34
35
36
37
38
39
40
41
# File 'lib/api_cache/abstract_store.rb', line 34

def expired?(key, timeout)
  if (created_at = created_at(key))
    Time.now - created_at > timeout
  else
    # If the created_at data is missing assume expired
    true
  end
end

#get(key) ⇒ Object

Get value.



13
14
15
# File 'lib/api_cache/abstract_store.rb', line 13

def get(key)
  raise "Method not implemented. Called abstract class."
end

#set(key, value) ⇒ Object

Set value. Returns true if success.



8
9
10
# File 'lib/api_cache/abstract_store.rb', line 8

def set(key, value)
  raise "Method not implemented. Called abstract class."
end