Class: CacheLocal::Process
- Inherits:
-
Object
- Object
- CacheLocal::Process
- Defined in:
- lib/cache_local/process.rb
Instance Method Summary collapse
- #delete(key) ⇒ Object
- #get(key) ⇒ Object
-
#initialize(namespace = nil) ⇒ Process
constructor
A new instance of Process.
- #set(key, value, expiration_time = 0) ⇒ Object
Constructor Details
#initialize(namespace = nil) ⇒ Process
Returns a new instance of Process.
3 4 5 6 |
# File 'lib/cache_local/process.rb', line 3 def initialize(namespace = nil) @namespace = namespace @cache = {@namespace => {}} end |
Instance Method Details
#delete(key) ⇒ Object
23 24 25 |
# File 'lib/cache_local/process.rb', line 23 def delete(key) @cache[@namespace].delete(key) end |
#get(key) ⇒ Object
12 13 14 15 16 17 18 19 20 21 |
# File 'lib/cache_local/process.rb', line 12 def get(key) return nil unless @cache[@namespace][key] if expired?(key) delete(key) return nil end @cache[@namespace][key][:value] end |
#set(key, value, expiration_time = 0) ⇒ Object
8 9 10 |
# File 'lib/cache_local/process.rb', line 8 def set(key, value, expiration_time = 0) @cache[@namespace][key] = {value: value, expiration_time: expiration_time, set_time: Time.now} end |