Class: PuppetLibrary::Http::Cache::InMemory
- Inherits:
-
Object
- Object
- PuppetLibrary::Http::Cache::InMemory
- Defined in:
- lib/puppet_library/http/cache/in_memory.rb
Defined Under Namespace
Constant Summary collapse
- ARBITRARY_CACHE_TTL_SECONDS =
10
Instance Method Summary collapse
- #clear ⇒ Object
- #get(key = "entry") ⇒ Object
-
#initialize(seconds_to_live = ARBITRARY_CACHE_TTL_SECONDS) ⇒ InMemory
constructor
A new instance of InMemory.
- #retrieve(key) ⇒ Object
- #save(key, entry) ⇒ Object
Constructor Details
#initialize(seconds_to_live = ARBITRARY_CACHE_TTL_SECONDS) ⇒ InMemory
Returns a new instance of InMemory.
22 23 24 |
# File 'lib/puppet_library/http/cache/in_memory.rb', line 22 def initialize(seconds_to_live = ARBITRARY_CACHE_TTL_SECONDS) @reaper = Reaper.new(seconds_to_live) end |
Instance Method Details
#clear ⇒ Object
45 46 47 |
# File 'lib/puppet_library/http/cache/in_memory.rb', line 45 def clear @cache.clear end |
#get(key = "entry") ⇒ Object
26 27 28 29 30 31 32 33 34 35 |
# File 'lib/puppet_library/http/cache/in_memory.rb', line 26 def get(key = "entry") entry = retrieve(key) if entry return entry.value unless @reaper.wants_to_kill? entry end value = yield save(key, Entry.new(value)) return value end |
#retrieve(key) ⇒ Object
37 38 39 |
# File 'lib/puppet_library/http/cache/in_memory.rb', line 37 def retrieve(key) cache[key] end |
#save(key, entry) ⇒ Object
41 42 43 |
# File 'lib/puppet_library/http/cache/in_memory.rb', line 41 def save(key, entry) cache[key] = entry end |