Cache a rate for future use
172421
def cache_rate(self, currency, date, rate):
        
        if not self.is_supported(defaults.INTERNAL_CURRENCY):
            logger.info('Tried to cache unsupported currency "{}". Ignoring.'.format(currency))
        else:
            cache.set(_cache_key(currency, date), str(rate), _cache_timeout(date))
548791
function CacheUpdate(bit, hash, state) {
  this.bit = bit;
  this.hash = hash;
  this.state = state;
}
245235
def _cached_same_codes(self):
        """"""
        cache_file = self._same_cache_file
        if os.path.exists(cache_file):
            maxage = datetime.now() - timedelta(minutes=4320)
            file_ts = datetime.fromtimestamp(os.stat(cache_file).st_mtime)
            if file_ts > maxage:
                try:
                    cache = open(cache_file, 'rb')
                    self._samecodes = cPickle.load(cache)
                    cache.close()
                    return True
                finally:
                    pass
        self.reload()
1270720
def update_cache(self, data=None):
        
        if data:
            self.cache_data = data
        self.cache_updated = timezone.now()
        self.save()
1213961
def cache_for(**timedelta_kw):
    
    max_age_timedelta = timedelta(**timedelta_kw)

    def decorate_func(func):
        @wraps(func)
        def decorate_func_call(*a, **kw):
            callback = SetCacheControlHeadersFromTimedeltaCallback(max_age_timedelta)
            registry_provider = AfterThisRequestCallbackRegistryProvider()
            registry = registry_provider.provide()
            registry.add(callback)
            return func(*a, **kw)
        return decorate_func_call
    return decorate_func
495981
def set(self, key, *args):
        """"""
        return self.cache.set(self._hashed(key), *args)
589636
def _cache(self, key, val):
        
        cache_size = (1 if util.dimensionless_contents(self.streams, self.kdims)
                      else self.cache_size)
        if len(self) >= cache_size:
            first_key = next(k for k in self.data)
            self.data.pop(first_key)
        self[key] = val
606013
def cache(self):
    """"""
    if not self._bucket_width or self._untrusted_time is None:
      raise ValueError('QueryCompute must be initialized with a bucket_width '
                       'and an untrusted_time in order to write to the cache.')

    now = datetime.datetime.now()
    untrusted_time = now - datetime.timedelta(seconds=self._untrusted_time)
    list(self._query_cache.compute_and_cache_missing_buckets(
        self._start_time,
        self._end_time,
        untrusted_time))
1220268
def _write_to_cache(self, expr, res):
        """"""
        res = dedent(res)
        super()._write_to_cache(expr, res)
708320
public void cache(String key, Object o, int ttl, Object... args) {
        if (conf().cacheDisabled()) return;
        ICacheService cacheService = _cacheService;
        Serializable value = null == o ? "" : (o instanceof Serializable ? (Serializable) o : o.toString());
        if (args.length > 0) {
            StringBuilder sb = new StringBuilder(key);
            for (Object arg : args) {
                sb.append("-").append(arg);
            }
            key = sb.toString();
        }
        cacheService.put(key, value, ttl);
    }
420256
def cache(self, con):
        """"""
        if self._maxusage and con.usage_count > self._maxusage:
            self._connections -=1
            logging.debug('dropping connection %s uses past max usage %s' % (con.usage_count, self._maxusage))
            con._close()
            return
        self._condition.acquire()
        if con in self._idle_cache:
            # called via socket close on a connection in the idle cache
            self._condition.release()
            return
        try:
            if not self._maxcached or len(self._idle_cache) < self._maxcached:
                # the idle cache is not full, so put it there
                self._idle_cache.append(con)
            else: # if the idle cache is already full,
                logging.debug('dropping connection. connection pool (%s) is full. maxcached %s' % (len(self._idle_cache), self._maxcached))
                con._close() # then close the connection
            self._condition.notify()
        finally:
            self._connections -= 1
            self._condition.release()
220044
def cached(key, path_info, details, locals)
      name, prefix, partial = path_info

      if key
        @cache.cache(key, name, prefix, partial, locals) do
          yield
        end
      else
        yield
      end
    end
631110
def cache_data(self):
        
        # Set Slug if not set
        if not self.slug_name:
            self.slug_name = slugify(self.name).strip()
            if len(self.slug_name) > 255:
                self.slug_name = self.slug_name[0:254]
241158
def apply_caching(response):
    """"""
    for k, v in config.get('HTTP_HEADERS').items():
        response.headers[k] = v
    return response
157936
def set(self, val, lifetime=None):
        
        cache.set(self.key,
                  (json.dumps(val) if self.serialize else val),
                  lifetime or settings.DEFAULT_CACHE_EXPIRE_TIME)
        return val
635146
function (key, intervalSize, limit) {
        var deferred = Q.defer()
            , memcached = Shared.memcached();
        if (!memcached) {
            deferred.reject();
        }
        else {
            //Get current rate for ip
            memcached.get(key, function (err, value) {
                if (err) {
                    //Allow access as failover
                    Logger.warn("Rate limit set but memcached error, allow access without limit", err);
                    deferred.reject();
                }
                else if (_.isUndefined(value)) {
                    memcached.set(key, 1, 60 * intervalSize, function (err) {
                        if (err) {
                            Logger.warn("Rate limit set but memcached error, allow access without limit", err);
                        }
                    });
                    deferred.resolve(1);
                }
                else {
                    //Do not increase rate counter if exceeded anyway
                    if (value < limit) {
                        // Increase rate counter by 1
                        memcached.incr(key, 1, function (err) {
                            if (err) {
                                Logger.warn("Rate limit set but memcached error, allow access without limit", err);
                            }
                        });
                    }
                    deferred.resolve(value + 1);
                }
            });
        }
        return deferred.promise;
    }
392811
def cache(self, con):
        """"""
        self._lock.acquire()
        try:
            if not self._maxcached or len(self._idle_cache) < self._maxcached:
                con._reset(force=self._reset)  # rollback possible transaction
                # the idle cache is not full, so put it there
                self._idle_cache.append(con)  # append it to the idle cache
            else:  # if the idle cache is already full,
                con.close()  # then close the connection
            self._connections -= 1
            self._lock.notify()
        finally:
            self._lock.release()