Class: Luoma::ThreadSafeLRUCache

Inherits:
LRUCache
  • Object
show all
Includes:
MonitorMixin
Defined in:
lib/luoma/cache.rb,
sig/luoma/cache.rbs

Overview

A thread safe least recently used cache.

Instance Attribute Summary

Attributes inherited from LRUCache

#max_size

Instance Method Summary collapse

Constructor Details

#initialize(max_size = 128) ⇒ ThreadSafeLRUCache

Returns a new instance of ThreadSafeLRUCache.

Parameters:

  • max_size (::Integer) (defaults to: 128)


52
53
54
# File 'lib/luoma/cache.rb', line 52

def initialize(max_size = 128)
  super
end

Instance Method Details

#[](key) ⇒ Object

Parameters:

  • key (Object)

Returns:

  • (Object)


56
57
58
59
60
# File 'lib/luoma/cache.rb', line 56

def [](key)
  synchronize do
    unsafe_get(key)
  end
end

#[]=(key, value) ⇒ Object

Parameters:

  • key (Object)
  • value (Object)

Returns:

  • (Object)


62
63
64
65
66
# File 'lib/luoma/cache.rb', line 62

def []=(key, value)
  synchronize do
    unsafe_set(key, value)
  end
end

#keysArray[Integer]

Returns:

  • (Array[Integer])


74
75
76
77
78
# File 'lib/luoma/cache.rb', line 74

def keys
  synchronize do
    unsafe_keys
  end
end

#lengthInteger

Returns:

  • (Integer)


68
69
70
71
72
# File 'lib/luoma/cache.rb', line 68

def length
  synchronize do
    unsafe_length
  end
end

#unsafe_getObject



47
# File 'lib/luoma/cache.rb', line 47

alias unsafe_get []

#unsafe_keysObject



50
# File 'lib/luoma/cache.rb', line 50

alias unsafe_keys keys

#unsafe_lengthObject



49
# File 'lib/luoma/cache.rb', line 49

alias unsafe_length length

#unsafe_setObject



48
# File 'lib/luoma/cache.rb', line 48

alias unsafe_set []=