Class: Cerner::OAuth1a::Cache::DefaultCache
- Inherits:
-
Cerner::OAuth1a::Cache
- Object
- Cerner::OAuth1a::Cache
- Cerner::OAuth1a::Cache::DefaultCache
- Defined in:
- lib/cerner/oauth1a/cache.rb
Overview
Internal: The default implementation of the Cerner::OAuth1a::Cache interface. This implementation just maintains a capped list of entries in memory.
Constant Summary
Constants inherited from Cerner::OAuth1a::Cache
Instance Method Summary collapse
-
#get(namespace, key) ⇒ Object
Internal: Gets an entry from the cache.
-
#initialize(max:) ⇒ DefaultCache
constructor
Internal: Constructs an instance.
-
#put(namespace, key, entry) ⇒ Object
Internal: Puts an entry into the cache.
Methods inherited from Cerner::OAuth1a::Cache
#full_key, instance, instance=
Constructor Details
#initialize(max:) ⇒ DefaultCache
Internal: Constructs an instance.
70 71 72 73 74 75 |
# File 'lib/cerner/oauth1a/cache.rb', line 70 def initialize(max:) super() @max = max @lock = Mutex.new @entries = {} end |
Instance Method Details
#get(namespace, key) ⇒ Object
Internal: Gets an entry from the cache.
88 89 90 91 92 93 |
# File 'lib/cerner/oauth1a/cache.rb', line 88 def get(namespace, key) @lock.synchronize do prune_expired(Time.now.utc.to_i) @entries[full_key(namespace, key)] end end |
#put(namespace, key, entry) ⇒ Object
Internal: Puts an entry into the cache.
78 79 80 81 82 83 84 85 |
# File 'lib/cerner/oauth1a/cache.rb', line 78 def put(namespace, key, entry) @lock.synchronize do now = Time.now.utc.to_i prune_expired(now) @entries[full_key(namespace, key)] = entry prune_size end end |