<commit_before>require 'resque'
module CacheBar
  module DataStore
    class Redis < AbstractDataStore
      def response_exists?
        client.exists(cache_key_name)
      end
      
      def get_response
        JSON.parse(client.get(cache_key_name), symbolize_names: true)
      end
      
      def store_response(response_hash, interval)
        client.setex(cache_key_name, interval, response_hash.to_json)
      end
      
      def backup_exists?
        client.exists(backup_key_name) && client.hexists(backup_key_name, uri_hash)
      end
      
      def get_backup
        JSON.parse(client.hget(backup_key_name, uri_hash), symbolize_names: true)
      end

      def store_backup(response_hash, interval)
        client.hset(backup_key_name, uri_hash, response_hash.to_json)
      end

      def update_async(url, interval, headers)
        Rails.logger.debug("[HTTPCache]: Update async #{cache_key_name}-#{url}")
        Resque.enqueue(UpdateRedisCache, cache_key_name, backup_key_name, uri_hash, url, interval, headers)
      end

      class UpdateRedisCache
        @queue = :update_redis_cache
        def self.perform(cache_key_name, backup_key_name, uri_hash, url, interval, headers)
          Resque.logger.info "[HTTPCache]: Updating #{url}"
          response_body = HTTParty.get(url, {cache: false, headers: headers}).parsed_response
        end
      end
    end
  end
end<commit_msg>Update logger<commit_after>require 'resque'
module CacheBar
  module DataStore
    class Redis < AbstractDataStore
      def response_exists?
        client.exists(cache_key_name)
      end
      
      def get_response
        JSON.parse(client.get(cache_key_name), symbolize_names: true)
      end
      
      def store_response(response_hash, interval)
        client.setex(cache_key_name, interval, response_hash.to_json)
      end
      
      def backup_exists?
        client.exists(backup_key_name) && client.hexists(backup_key_name, uri_hash)
      end
      
      def get_backup
        JSON.parse(client.hget(backup_key_name, uri_hash), symbolize_names: true)
      end

      def store_backup(response_hash, interval)
        client.hset(backup_key_name, uri_hash, response_hash.to_json)
      end

      def update_async(url, interval, headers)
        HTTParty::HTTPCache.logger.debug("[HTTPCache]: Update async #{cache_key_name}-#{url}")
        Resque.enqueue(UpdateRedisCache, cache_key_name, backup_key_name, uri_hash, url, interval, headers)
      end

      class UpdateRedisCache
        @queue = :update_redis_cache
        def self.perform(cache_key_name, backup_key_name, uri_hash, url, interval, headers)
          HTTParty::HTTPCache.logger.debug "[HTTPCache]: Updating #{url}"
          response_body = HTTParty.get(url, {cache: false, headers: headers}).parsed_response
        end
      end
    end
  end
end
{'fraction_non_alphanumeric': 0.08280701754385965, 'fraction_numerical': 0.0, 'mean_word_length': 2.9707520891364902, 'pattern_counts': {'":': 0, '<': 5, '<?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': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3081598', 'n_tokens_mistral': 884, 'n_tokens_neox': 885, 'n_words': 176}