Sha256: 8b4391920dafe56c80a401628846deac65678c9bf5d35072bea7d49312cd8b8c
Contents?: true
Size: 1.07 KB
Versions: 18
Compression:
Stored size: 1.07 KB
Contents
# Copyright (c) 2023 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 # Initializes new Least Recently Used Cache Store # # @raise [StandardError] raises error if provided capacity is invalid or less or equal to zero 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
18 entries across 18 versions & 1 rubygems