Sha256: fe642b3bd6e7c68b67543d5b5418e22110a1753af0fc0187acd5cb36403e9417

Contents?: true

Size: 493 Bytes

Versions: 3

Compression:

Stored size: 493 Bytes

Contents

# frozen_string_literal: true

module Split
  class Cache

    def self.clear
      @cache = nil
    end

    def self.fetch(namespace, key)
      return yield unless Split.configuration.cache

      @cache ||= {}
      @cache[namespace] ||= {}

      value = @cache[namespace][key]
      return value if value

      @cache[namespace][key] = yield
    end

    def self.clear_key(key)
      @cache&.keys&.each do |namespace|
        @cache[namespace]&.delete(key)
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
split-4.0.1 lib/split/cache.rb
split-4.0.0.pre2 lib/split/cache.rb
split-4.0.0.pre lib/split/cache.rb