Sha256: 83337027bdd19eeecce7a0b0dd6169bcbcf9cfff2715f7f755cff15a2594d068
Contents?: true
Size: 925 Bytes
Versions: 6
Compression:
Stored size: 925 Bytes
Contents
# Copyright (c) 2022 Contrast Security, Inc. See https://www.contrastsecurity.com/enduser-terms-0317a for more details. # frozen_string_literal: true module Contrast module Utils # A LRU(Least Recently Used) Cache store. class LRUCache def initialize capacity = 500 raise StandardError 'Capacity must be bigger than 0' if capacity <= 0 @capacity = capacity @cache = {} end def [] key val = @cache.delete(key) @cache[key] = val if val val end def []= key, value @cache.delete(key) @cache[key] = value @cache.shift if @cache.size > @capacity value # rubocop:disable Lint/Void end def keys @cache.keys end def key? key @cache.key?(key) end def values @cache.values end def clear @cache.clear end end end end
Version data entries
6 entries across 6 versions & 1 rubygems