TODO: new cache mechanism using format string
8263
def parse(value)
      unless value.is_a?(String)
        raise TimeParseError, "value must be string: #{value}"
      end

      if @cache1_key == value
        return @cache1_time
      elsif @cache2_key == value
        return @cache2_time
      else
        begin
          time = @parse.call(value)
        rescue => e
          raise TimeParseError, "invalid time format: value = #{value}, error_class = #{e.class.name}, error = #{e.message}"
        end
        @cache1_key = @cache2_key
        @cache1_time = @cache2_time
        @cache2_key = value
        @cache2_time = time
        return time
      end
    end
605643
@Override
    public synchronized String format(LogRecord record) {
        cachedDate.setTime(record.getMillis());
        final StringBuilder sb = new StringBuilder();
        sb.append(cachedFormat.format(cachedDate));
        sb.append(" [").append(Thread.currentThread().getName()).append("]");
        sb.append(" ").append(record.getLevel().getName());
        sb.append(" (");
        final String className = record.getSourceClassName();
        if (className != null) {
            if (className.contains(".")) {
                sb.append(className.substring(className.lastIndexOf(".") + ".".length()));
            } else {
                sb.append(className);
            }
            final String methodName = record.getSourceMethodName();
            if (methodName != null) {
                sb.append("@").append(methodName).append("()");
            }
        } else {
            sb.append(record.getLoggerName());
        }
        sb.append(") - ").append(formatMessage(record));
        final Throwable thrown = record.getThrown();
        if (thrown != null) {
            final StringWriter stringWriter = new StringWriter();
            final PrintWriter printWriter = new PrintWriter(stringWriter);
            try {
                printWriter.println();
                thrown.printStackTrace(printWriter);
            } finally {
                printWriter.close();
            }
            sb.append(stringWriter.toString());
        }
        sb.append("\n");
        return sb.toString();
    }
1175368
private String makeHash(String request) throws CacheException {
        RequestCtx reqCtx = null;
        try {
            reqCtx = m_contextUtil.makeRequestCtx(request);
        } catch (MelcoeXacmlException pe) {
            throw new CacheException("Error converting request", pe);
        }
        byte[] hash = null;
        // ensure thread safety, don't want concurrent invocations of this method all modifying digest at once
        // (alternative is to construct a new digest for each(
        synchronized(digest) {
            digest.reset();

            hashSubjectList(reqCtx.getSubjectsAsList(), digest);

            hashAttributeList(reqCtx.getResourceAsList(), digest);

            hashAttributeList(reqCtx.getActionAsList(), digest);

            hashAttributeList(reqCtx.getEnvironmentAttributesAsList(), digest);

            hash = digest.digest();
        }

        return byte2hex(hash);
    }
298109
def decode_string(self, string, cache, as_map_key):
        
        if is_cache_key(string):
            return self.parse_string(cache.decode(string, as_map_key),
                                     cache, as_map_key)
        if is_cacheable(string, as_map_key):
            cache.encode(string, as_map_key)
        return self.parse_string(string, cache, as_map_key)
665925
function(src, stringToFind, stringToReplace) {

      var temp, index;

      temp = src;
      index = temp.indexOf(stringToFind);

      while (index != -1) {
        temp = temp.replace(stringToFind, stringToReplace);
        index = temp.indexOf(stringToFind);
      }

      return temp;
    }
1337681
def to_s(data = {})
      return @_cache unless undefined_size? || !@_cache
      return "x" * (tags[:size] || 1) if name == :null

      out = case tags[:type]
      when :short
        modify_if_needed "S"
      when :int
        modify_if_needed "I"
      when :long
        modify_if_needed "L"
      when :string
        handle_string_type
      when :float
        handle_float_type
      when nil
        handle_empty_type
      else
        nil
      end

      if tags[:size].is_a? Symbol
        out << data.fetch(tags[:size]).to_s
      elsif tags[:size] && ![:null, nil].include?(tags[:type])
        out << tags[:size].to_s
      end

      out
    end
1160324
def inheritable_cache_set(formats, name, partial, param, prefix)
      formats.each do |format|
        # assign hash default values to respective key 
        inheritable_cache[format.to_sym] = hf = inheritable_cache[format.to_sym]
        hf[partial] = hp = hf[partial]
        hp[name] = hn = hp[name]
        # finally store prefix in the deepest hash
        hn[param] = prefix
      end
    end
1285460
function __getSetCacheResults(o) {

  var self = this,
      storage = o.storage,
      cacheID = o.cacheID,
      cacheFilter = o.cacheFilter,
      method = o.method,
      args = o.args,
      callback = o.callback,
      timeout = o.timeout;

  // See if cache is available
  storage.get(cacheID, function(err, data) {
    
    if (err) {
      
      callback.call(self, err, null);
      
    } else {
      
      if ( data ) {
        
        // Object found in cache
        
        // Run callback with cached array
        var results = JSON.parse(data);
        if (app.debugLog) app.debug("Using cached data for " + cacheID);
        callback.apply(self, results);
        
      } else {
        
        // Cache new data
        
        self[method].apply(self, args.concat([function(err) {
          
          if (err) {
            
            callback.call(self, err, null);
            
          } else {
            
            // Get results array from arguments
            var results = slice.call(arguments, 0);
            
            // Run cache filter if available
            if (cacheFilter instanceof Function) {
              results = cacheFilter.apply(self, results);
            }
            
            // Set cache data
            storage.set(cacheID, JSON.stringify(results), function(err) {
              
              if (err) {
                
                callback.call(self, err, null);

              } else {
                
                // If timeout available, set expiration
                if (timeout && typeof timeout == 'number') {
                  
                  // Set cache expiration
                  storage.expire(cacheID, timeout, function(err) {
                    
                    if (err) callback.call(self, err, null);
                    
                    else {
                      
                      // Run callback with results array (after expiration set)
                      if (app.debugLog) app.debug(util.format("Cached new data for %s (expires in %d seconds)", cacheID, timeout));
                      callback.apply(self, results);
                      
                    }
                    
                  });
                  
                } else {
                  
                  // Run callback with results array
                  if (app.debugLog) app.debug("Cached new data for " + cacheID);
                  callback.apply(self, results);  
                  
                }
                
              }
            });
          }
        }]));
        
      }
    }
    
  });

}
770257
function memoize(key, val) {
  if (cache.hasOwnProperty(key)) {
    return cache[key];
  }
  return (cache[key] = val);
}
184164
function (str) {
    if (caches[str]) {
      return caches[str];
    }
    
    // special regexp chars (., +, etc.)
    reg = str.replace(/[.+^$()|{}]/g, function (match, offset, s) {
      return s[offset - 1] === '\\' ? match : '\\' + match;
    });
    // ? and *
    reg = reg.replace(/[?*]/g, function (match, offset, s) {
      if (s[offset - 1] === '\\') {
        return match;
      }
      return match === '?' ? '.' : '.*';
    });
    // special regexp escapings (\d, \S, etc.)
    // https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/RegExp
    reg = reg.replace(/\\([dDsSwWtrnvfbB0cxu])/g, '$1');
    return caches[str] = new RegExp('^' + reg + '$');
  }
952749
function createRegexString(prefix) {
  var key = 'createRegexString:' + prefix;
  if (cache.hasOwnProperty(key)) {
    return cache[key];
  }
  var str = (prefix + '(\\d+)$}').replace(/\\?([${}])/g, '\\$1');
  cache[key] = str;
  return str;
}
881015
def read_regexp
      string = read_string(cache: false)
      options = read_byte

      result = Regexp.new(string, options)
      @object_cache << result
      result
    end
545416
private <T> T getCached(String prefix, String postfix, Class<T> cls) {
    return cls.cast(cache.get(prefix + '.' + postfix));
  }
453684
function lessCached(filename, options) {
  if (options.cache === 'dynamic') {
    throw new Error('Dynamic cache still needs implimenting');
    if (cache[filename]) {
      return cache[filename].then(function (result) {
        
      });
    } else {
      return cache[filename] = lessInternal(filename, options);
    }
  } else if (options.cache) {
    if (cache[filename]) return cache[filename];
    else return cache[filename] = lessInternal(filename, options);
  } else {
    return lessInternal(filename, options);
  }
}
141793
private static synchronized void addToCache(Cache cache, byte[] encoding,
            Object value) {
        if (encoding.length > ENC_MAX_LENGTH) {
            return;
        }
        Object key = new Cache.EqualByteArray(encoding);
        cache.put(key, value);
    }
550547
function toRegex(prefix) {
  var key = appendPrefix(prefix, '(\\d+)');
  if (cache.hasOwnProperty(key)) {
    return cache[key];
  }
  var regex = new RegExp(createRegexString(key), 'g');
  cache[key] = regex;
  return regex;
}
377575
def format(
        self,
        format_string,
        module=None,
        param_dict=None,
        force_composite=False,
        attr_getter=None,
    ):
        
        # fix python 2 unicode issues
        if python2 and isinstance(format_string, str):
            format_string = format_string.decode("utf-8")

        if param_dict is None:
            param_dict = {}

        # if the processed format string is not in the cache then create it.
        if format_string not in self.block_cache:
            self.build_block(format_string)

        first_block = self.block_cache[format_string]

        def get_parameter(key):
            """
            function that finds and returns the value for a placeholder.
            """
            if key in param_dict:
                # was a supplied parameter
                param = param_dict.get(key)
            elif module and hasattr(module, key):
                param = getattr(module, key)
                if hasattr(param, "__call__"):
                    # we don't allow module methods
                    raise Exception()
            elif attr_getter:
                # get value from attr_getter function
                try:
                    param = attr_getter(key)
                except:  # noqa e722
                    raise Exception()
            else:
                raise Exception()
            if isinstance(param, Composite):
                if param.text():
                    param = param.copy()
                else:
                    param = u""
            elif python2 and isinstance(param, str):
                param = param.decode("utf-8")
            return param

        # render our processed format
        valid, output = first_block.render(get_parameter, module)

        # clean things up a little
        if isinstance(output, list):
            output = Composite(output)
        if not output:
            if force_composite:
                output = Composite()
            else:
                output = ""

        return output