<commit_before>require 'memcached'

module Juno
  module Adapters
    # Memcached backend (using gem memcached)
    # @api public
    class MemcachedNative < Base
      # Constructor
      #
      # @param [Hash] options
      #
      # Options:
      # * :server - Memcached server (default localhost:11211)
      # * :namespace - Key namespace
      # * Other options passed to Memcached#new
      def initialize(options = {})
        server = options.delete(:server) || 'localhost:11211'
        options.merge!(:prefix_key => options.delete(:namespace)) if options[:namespace]
        @cache = ::Memcached.new(server, options)
      end

      def key?(key, options = {})
        @cache.get(key, false)
        true
      rescue ::Memcached::NotFound
        false
      end

      def load(key, options = {})
        value = @cache.get(key, false)
        if value && options.include?(:expires)
          store(key, value, options)
        else
          value
        end
      rescue ::Memcached::NotFound
      end

      def delete(key, options = {})
        value = @cache.get(key, false)
        @cache.delete(key)
        value
      rescue ::Memcached::NotFound
      end

      def store(key, value, options = {})
        @cache.set(key, value, options[:expires] || @cache.options[:default_ttl], false)
        value
      end

      def clear(options = {})
        @cache.flush
        self
      end
    end
  end
end<commit_msg>MemcachedNative: set default_ttl for jruby-memcached<commit_after>require 'memcached'

module Juno
  module Adapters
    # Memcached backend (using gem memcached)
    # @api public
    class MemcachedNative < Base
      # Constructor
      #
      # @param [Hash] options
      #
      # Options:
      # * :server - Memcached server (default localhost:11211)
      # * :namespace - Key namespace
      # * Other options passed to Memcached#new
      def initialize(options = {})
        server = options.delete(:server) || 'localhost:11211'
        options.merge!(:prefix_key => options.delete(:namespace)) if options[:namespace]
        @default_ttl = options[:default_ttl] || 604800
        @cache = ::Memcached.new(server, options)
      end

      def key?(key, options = {})
        @cache.get(key, false)
        true
      rescue ::Memcached::NotFound
        false
      end

      def load(key, options = {})
        value = @cache.get(key, false)
        if value && options.include?(:expires)
          store(key, value, options)
        else
          value
        end
      rescue ::Memcached::NotFound
      end

      def delete(key, options = {})
        value = @cache.get(key, false)
        @cache.delete(key)
        value
      rescue ::Memcached::NotFound
      end

      def store(key, value, options = {})
        # TTL must be Fixnum
        @cache.set(key, value, options[:expires] || @default_ttl, false)
        value
      end

      def clear(options = {})
        @cache.flush
        self
      end
    end
  end
end
{'fraction_non_alphanumeric': 0.11218697829716194, 'fraction_numerical': 0.008681135225375626, 'mean_word_length': 2.0602655771195098, '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': '2961650', 'n_tokens_mistral': 874, 'n_tokens_neox': 861, 'n_words': 220}