<commit_before>require 'singleton'

module Capistrano
  module RightScale
    class Cache
      include Singleton

      attr_accessor :lifetime
      attr_reader :array, :array_instances, :deployment
      def initialize
        @lifetime = 86400
      end

      def load_server_cache(role, prefix=nil)
         server_cache = self.instance_variable_get("@#{role}_cache")

         begin
           cache_files = Dir.glob("#{Dir.tmpdir}/cap-rightscale-#{ENV['USER']}-*/#{prefix}*#{role}.cache")

           if cache_files.size > 0 && !server_cache
             c = Marshal.load(open(cache_files.first) {|f| f.read})
             self.instance_variable_set("@#{role}_cache", c)
           end
           server_cache = self.instance_variable_get("@#{role}_cache")
           return [] unless server_cache # No cache entry

           # get servers
           if Time.now - server_cache[role][:cache] > lifetime
             server_list = []
           elsif server_cache[role][:servers]
             server_list = server_cache[role][:servers]
           else
             server_list = []
           end
         rescue => e
           return [] unless server_cache
         end

         server_list
      end

      def dump_server_cache(role, servers, prefix=nil)
        h = {role => {:servers => servers, :cache => Time.now}}<commit_msg>add message of cache has expired<commit_after>require 'singleton'

module Capistrano
  module RightScale
    class Cache
      include Singleton

      attr_accessor :lifetime
      attr_reader :array, :array_instances, :deployment
      def initialize
        @lifetime = 86400
      end

      def load_server_cache(role, prefix=nil)
         server_cache = self.instance_variable_get("@#{role}_cache")

         begin
           cache_files = Dir.glob("#{Dir.tmpdir}/cap-rightscale-#{ENV['USER']}-*/#{prefix}*#{role}.cache")

           if cache_files.size > 0 && !server_cache
             c = Marshal.load(open(cache_files.first) {|f| f.read})
             self.instance_variable_set("@#{role}_cache", c)
           end
           server_cache = self.instance_variable_get("@#{role}_cache")
           return [] unless server_cache # No cache entry

           # get servers
           if Time.now - server_cache[role][:cache] > lifetime
             STDERR.puts("The cache of server list has expired.")
             server_list = []
           elsif server_cache[role][:servers]
             server_list = server_cache[role][:servers]
           else
             server_list = []
           end
         rescue => e
           return [] unless server_cache
         end

         server_list
      end

      def dump_server_cache(role, servers, prefix=nil)
        h = {role => {:servers => servers, :cache => Time.now}}
{'fraction_non_alphanumeric': 0.108985925658607, 'fraction_numerical': 0.004330566582461205, 'mean_word_length': 2.128668171557562, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 15, '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': '3866254', 'n_tokens_mistral': 795, 'n_tokens_neox': 787, 'n_words': 171}