<commit_before>require 'peek/adapters/base'
require 'dalli'

module Peek
  module Adapters
    class Memcache < Base
      def initialize(options = {})
        @client = options.fetch(:client, ::Dalli::Client.new)
        @expires_in = options.fetch(:expires_in, 60 * 30)
      end

      def get(request_id)
        @client.get("peek:requests:#{request_id}")
      end

      def save
        @client.add("peek:requests:#{Peek.request_id}", Peek.results.to_json, @expires_in)
      end
    end
  end
end<commit_msg>Rescue & log Dalli exceptions instead of crashing<commit_after>require 'peek/adapters/base'
require 'dalli'

module Peek
  module Adapters
    class Memcache < Base
      def initialize(options = {})
        @client = options.fetch(:client, ::Dalli::Client.new)
        @expires_in = options.fetch(:expires_in, 60 * 30)
      end

      def get(request_id)
        @client.get("peek:requests:#{request_id}")
      rescue ::Dalli::DalliError => e
        Rails.logger.error "#{e.class.name}: #{e.message}"
      end

      def save
        @client.add("peek:requests:#{Peek.request_id}", Peek.results.to_json, @expires_in)
      rescue ::Dalli::DalliError => e
        Rails.logger.error "#{e.class.name}: #{e.message}"
      end
    end
  end
end
{'fraction_non_alphanumeric': 0.13549920760697307, 'fraction_numerical': 0.006339144215530904, 'mean_word_length': 2.8981481481481484, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, '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': '2859476', 'n_tokens_mistral': 445, 'n_tokens_neox': 423, 'n_words': 85}