<commit_before>require 'dalli'
require 'forwardable'

module Twigg
  module Cache
    class Client
      extend Forwardable
      def_delegators '@client', :get, :set

      def initialize
        options = {
          compress:        true,
          expires_in:      Config.cache.expiry,
          value_max_bytes: Config.cache.value_max_bytes,
          namespace:       Config.cache.namespace,
        }.delete_if { |key, value| value.nil? }

        @client = Dalli::Client.new("#{Config.cache.host}:#{Config.cache.port}",
                                    options)
      end
    end
  end
end<commit_msg>Make twigg-cache gem degrade gracefully in the absence of memcache<commit_after>require 'dalli'

module Twigg
  module Cache
    class Client
      def initialize
        options = {
          compress:        true,
          expires_in:      Config.cache.expiry,
          value_max_bytes: Config.cache.value_max_bytes,
          namespace:       Config.cache.namespace,
        }.delete_if { |key, value| value.nil? }

        @client = Dalli::Client.new("#{Config.cache.host}:#{Config.cache.port}",
                                    options)
      end

      def get(key)
        @client.get(key)
      rescue Dalli::RingError
        # degrade gracefully
      end

      def set(key, value)
        @client.set(key, value)
      rescue Dalli::RingError
        # degrade gracefully
      end
    end
  end
end
{'fraction_non_alphanumeric': 0.09243697478991597, 'fraction_numerical': 0.0, 'mean_word_length': 1.8241106719367588, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6603473', 'n_tokens_mistral': 423, 'n_tokens_neox': 404, 'n_words': 94}