Class: GoogleApi::Cache

Inherits:
Object
  • Object
show all
Defined in:
lib/google_api/cache.rb

Instance Method Summary collapse

Constructor Details

#initializeCache

Returns a new instance of Cache.



4
5
6
# File 'lib/google_api/cache.rb', line 4

def initialize
  @cache = {}
end

Instance Method Details

#delete(key) ⇒ Object



26
27
28
# File 'lib/google_api/cache.rb', line 26

def delete(key)
  @cache.delete(key)
end

#exists?(key) ⇒ Boolean

Returns:

  • (Boolean)


22
23
24
# File 'lib/google_api/cache.rb', line 22

def exists?(key)
  @cache.has_key?(key) && !expire?(key)
end

#read(key) ⇒ Object



14
15
16
17
18
19
20
# File 'lib/google_api/cache.rb', line 14

def read(key)
  if exists?(key)
    return @cache[key][0]
  end

  nil
end

#write(key, value, expire = 0) ⇒ Object



8
9
10
11
12
# File 'lib/google_api/cache.rb', line 8

def write(key, value, expire = 0)
  expire = expire == 0 ? 0 : Time.now + (expire * 60)

  @cache[key] = [value, expire]
end