<commit_before>require 'forwardable'

module Flipper
  module Adapters
    class Memoized
      extend Forwardable

      FeaturesKey = :flipper_features

      # Forward soon to be private adapter methods to source adapter
      def_delegators :@adapter, :read, :write, :delete,
        :set_members, :set_add, :set_delete

      # Public
      def initialize(adapter, cache = {})
        @adapter = adapter
        @cache = cache
      end

      # Public
      def get(feature)
        @cache.fetch(feature) {
          @cache[feature] = @adapter.get(feature)
        }
      end

      # Public
      def enable(feature, gate, thing)
        result = @adapter.enable(feature, gate, thing)
        @cache.delete(feature)
        result
      end

      # Public
      def disable(feature, gate, thing)
        result = @adapter.disable(feature, gate, thing)
        @cache.delete(feature)
        result
      end

      def features
        @cache.fetch(FeaturesKey) {
          @cache[FeaturesKey] = @adapter.features
        }
      end

      def add(feature)
        result = @adapter.add(feature)
        @cache.delete(FeaturesKey)
        result
      end
    end
  end
end<commit_msg>Added name and inspect to memoized.<commit_after>require 'forwardable'

module Flipper
  module Adapters
    class Memoized
      FeaturesKey = :flipper_features

      # Public: The name of the adapter.
      attr_reader :name

      # Public: The adapter that is being memoized.
      attr_reader :adapter

      # Public
      def initialize(adapter, cache = {})
        @adapter = adapter
        @name = :memoized
        @cache = cache
      end

      # Public
      def get(feature)
        @cache.fetch(feature) {
          @cache[feature] = @adapter.get(feature)
        }
      end

      # Public
      def enable(feature, gate, thing)
        result = @adapter.enable(feature, gate, thing)
        @cache.delete(feature)
        result
      end

      # Public
      def disable(feature, gate, thing)
        result = @adapter.disable(feature, gate, thing)
        @cache.delete(feature)
        result
      end

      def features
        @cache.fetch(FeaturesKey) {
          @cache[FeaturesKey] = @adapter.features
        }
      end

      def add(feature)
        result = @adapter.add(feature)
        @cache.delete(FeaturesKey)
        result
      end

      def unmemoize
        @cache.clear
      end

      def inspect
        attributes = [
          "name=#{name.inspect}",
          "adapter=#{adapter.inspect}",
          "cache=#{@cache.inspect}",
        ]
        "#<#{self.class.name}:#{object_id} #{attributes.join(', ')}>"
      end
    end
  end
end
{'fraction_non_alphanumeric': 0.09690644800596347, 'fraction_numerical': 0.0, 'mean_word_length': 1.873661670235546, 'pattern_counts': {'":': 0, '<': 4, '<?xml version=': 0, '>': 4, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7298163', 'n_tokens_mistral': 771, 'n_tokens_neox': 758, 'n_words': 188}