Class: JIRA::RequestCache

Inherits:
Object
  • Object
show all
Defined in:
lib/jira/request_cache.rb

Instance Method Summary collapse

Constructor Details

#initialize(time_to_live) ⇒ RequestCache

Returns a new instance of RequestCache.



5
6
7
# File 'lib/jira/request_cache.rb', line 5

def initialize(time_to_live)
  @time_to_live = time_to_live
end

Instance Method Details

#load(uri) ⇒ Object



9
10
11
12
13
14
15
16
17
18
19
20
21
# File 'lib/jira/request_cache.rb', line 9

def load(uri)
  key = cache_key(uri)
  cache_object = cache(uri)
  response = verify cache_object[key]

  if response == :expired
    cache_object.delete(key)
    cache_file(uri, 'w+').write(Marshal.dump(cache_object))
    nil
  else
    response
  end
end

#save(uri, response) ⇒ Object



23
24
25
26
27
28
29
30
31
32
33
# File 'lib/jira/request_cache.rb', line 23

def save(uri, response)
  now = Time.now.to_i

  new_cache = cache(uri)
  new_cache[cache_key(uri)] = {
    'data' => response,
    'timestamp' => now
  }

  cache_file(uri, 'w+b').write(Marshal.dump(new_cache))
end