Class: Safelylaunch::HttpCache
- Inherits:
-
Object
- Object
- Safelylaunch::HttpCache
- Defined in:
- lib/safelylaunch/http_cache.rb
Defined Under Namespace
Classes: Value
Instance Method Summary collapse
- #get(key) ⇒ Object
-
#initialize ⇒ HttpCache
constructor
A new instance of HttpCache.
-
#keys ⇒ Object
only for tests.
- #put(key, payload, expired_in) ⇒ Object
Constructor Details
#initialize ⇒ HttpCache
Returns a new instance of HttpCache.
7 8 9 |
# File 'lib/safelylaunch/http_cache.rb', line 7 def initialize @hash = Concurrent::Map.new end |
Instance Method Details
#get(key) ⇒ Object
16 17 18 19 20 21 22 23 24 25 |
# File 'lib/safelylaunch/http_cache.rb', line 16 def get(key) value = @hash[key] if value && (Time.new.to_i < value.expired_time) value.data else @hash.delete(key) nil end end |
#keys ⇒ Object
only for tests
28 29 30 |
# File 'lib/safelylaunch/http_cache.rb', line 28 def keys @hash.keys end |
#put(key, payload, expired_in) ⇒ Object
11 12 13 14 |
# File 'lib/safelylaunch/http_cache.rb', line 11 def put(key, payload, expired_in) @hash.put_if_absent(key, Value.new(Time.new.to_i + expired_in, payload)) payload end |