Class: OAuth2c::Cache::Backends::InMemoryLRU

Inherits:
Object
  • Object
show all
Defined in:
lib/oauth2c/cache/backends/in_memory_lru.rb

Instance Method Summary collapse

Constructor Details

#initialize(max_size) ⇒ InMemoryLRU

Returns a new instance of InMemoryLRU.



21
22
23
24
25
# File 'lib/oauth2c/cache/backends/in_memory_lru.rb', line 21

def initialize(max_size)
  @max_size = max_size
  @store = {}
  @mtx = Mutex.new
end

Instance Method Details

#lookup(key) ⇒ Object



27
28
29
30
31
32
# File 'lib/oauth2c/cache/backends/in_memory_lru.rb', line 27

def lookup(key)
  @mtx.synchronize do
    return nil unless @store.has_key?(key)
    @store[key] = @store.delete(key)
  end
end

#store(key, bucket) ⇒ Object



34
35
36
37
38
39
40
41
42
# File 'lib/oauth2c/cache/backends/in_memory_lru.rb', line 34

def store(key, bucket)
  @mtx.synchronize do
    @store[key] = bucket

    if @store.size > @max_size
      @store.shift
    end
  end
end