class LaunchDarkly::SimpleLRUCacheSet

A non-thread-safe implementation of a LRU cache set with only add and reset methods. Based on github.com/SamSaffron/lru_redux/blob/master/lib/lru_redux/cache.rb @private

Public Class Methods

new(capacity) click to toggle source
# File lib/ldclient-rb/simple_lru_cache.rb, line 7
def initialize(capacity)
  @values = {}
  @capacity = capacity
end

Public Instance Methods

add(value) click to toggle source

Adds a value to the cache or marks it recent if it was already there. Returns true if already there.

# File lib/ldclient-rb/simple_lru_cache.rb, line 13
def add(value)
  found = true
  @values.delete(value) { found = false }
  @values[value] = true
  @values.shift if @values.length > @capacity
  found
end
clear() click to toggle source
# File lib/ldclient-rb/simple_lru_cache.rb, line 21
def clear
  @values = {}
end