set cache by code, must set timeout length
505949
def set(key, value, timeout = -1, adapter = MemoryAdapter):
	'''
	
	'''
	if adapter(timeout = timeout).set(key, pickle.dumps(value)):
		return value
	else:
		return None
888135
function set(req) {
        var cache = caches[this.name];
        if (!cache) {
            cache = caches[this.name] = createLocalCache();
        }

        if (!redisOffline) {
            try {
                (req.value || !cache.del) ?
                    cache.set(req.key, req.value) :
                    cache.del(req.key);
            }
            catch (err) {
                console.log('redis set err: ' + err);
            }
        }
    }
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);
    }
38787
def set_status(self, instance, status):
        """"""
        status_key = self.get_status_key(instance)
        cache.set(status_key, status, timeout=300)
1187563
def cached(cls, timeout=60, cache_none=False):
        
        return CachedModel(cls=cls, timeout=timeout, cache_none=cache_none)
630452
function () {
		var updateCache = this.cache;
		for (var i = 0, n = updateCache.length; i < n; i++)
			updateCache[i].update();
	}
734258
def cache_page(**kwargs):
    
    cache_timeout = kwargs.pop('cache_timeout', None)
    key_prefix = kwargs.pop('key_prefix', None)
    cache_min_age = kwargs.pop('cache_min_age', None)
    decorator = decorators.decorator_from_middleware_with_args(CacheMiddleware)(
        cache_timeout=cache_timeout,
        key_prefix=key_prefix,
        cache_min_age=cache_min_age,
        **kwargs
    )
    return decorator
1330229
def with_cache(function):
        
        @wraps(function)
        def wrapped(cls, _cache_key, _cache_ignore, _cache_timeout, **kwargs):
            def clear_timeouts():
                """Clear the cache of timed out results."""
                for key in list(cls.timeouts):
                    if timer() - cls.timeouts[key] > _cache_timeout:
                        del cls.timeouts[key]
                        del cls.cache[key]

            if _cache_ignore:
                return function(cls, **kwargs)
            with cls.ca_lock:
                clear_timeouts()
                if _cache_key in cls.cache:
                    if cls.cache_hit_callback:
                        cls.cache_hit_callback(_cache_key)
                    return cls.cache[_cache_key]
            # Releasing the lock before actually making the request allows for
            # the possibility of more than one thread making the same request
            # to get through. Without having domain-specific caching (under the
            # assumption only one request to a domain can be made at a
            # time), there isn't a better way to handle this.
            result = function(cls, **kwargs)
            # The handlers don't call `raise_for_status` so we need to ignore
            # status codes that will result in an exception that should not be
            # cached.
            if result.status_code not in (200, 302):
                return result
            with cls.ca_lock:
                cls.timeouts[_cache_key] = timer()
                cls.cache[_cache_key] = result
                return result
        return wrapped
812580
def set_stat(self, key, value, timeout):
        
        if not self.cache:
            return
        key_list = self.cache.get(Conf.Q_STAT, [])
        if key not in key_list:
            key_list.append(key)
        self.cache.set(Conf.Q_STAT, key_list)
        return self.cache.set(key, value, timeout)
1063951
function setCache(context, config, stats, pathname) {
  if (!config.cache) {
    return
  }
  if (config.cache === true) {
    config.cache = CACHETIME
  }
  if ('number' !== typeof config.cache) {
    return
  }
  context.lastModified = stats.mtime.toUTCString()
  let date = new Date()
  let expires = new Date()
  let cacheTime = config.cache * 1000
  // 设置缓存过期时间;
  expires.setTime(expires.getTime() + cacheTime)
  context.set({
    Date: date.toUTCString(),
    Expires: expires.toUTCString(),
    'Cache-Control': `max-age=${cacheTime}`
  })
  if (config.etag) {
    let size = stats.size.toString(16)
    let mtime = stats.mtime.getTime().toString(16)
    context.etag = `${size}-${mtime}`
  }
}
1026831
public static function set($cacheloc, $cachekey, $cacheval, $expiresec=false)
    {
        $cacheloc = "cache_" . $cacheloc;
        if ( $cacheval === null || $cacheval === false ) {
            unset($_SESSION[$cacheloc]);
            return;
        }
        if ( $expiresec !== false ) $expiresec = time() + $expiresec;
        $_SESSION[$cacheloc] = array($cachekey, $cacheval, $expiresec);
    }
495981
def set(self, key, *args):
        """"""
        return self.cache.set(self._hashed(key), *args)
730728
def set_page_load_timeout(self, time_to_wait):
        
        try:
            self.execute(Command.SET_TIMEOUTS, {
                'pageLoad': int(float(time_to_wait) * 1000)})
        except WebDriverException:
            self.execute(Command.SET_TIMEOUTS, {
                'ms': float(time_to_wait) * 1000,
                'type': 'page load'})
1362165
public function setCache() {
        if (!file_exists($this->_fileName)) {
            file_put_contents($this->_fileName, $this->_compress(serialize($this->_content)));
        }

        $timeAgo = time() - filemtime($this->_fileName);

        if ($timeAgo > $this->_time) {
            file_put_contents($this->_fileName, $this->_compress(serialize($this->_content)));
        }
    }
909874
public void updateCacheSizes(long max, long current) {

        final String methodName = "updateCacheSizes()";

        if (tc.isDebugEnabled() && null != _maxInMemoryCacheEntryCount && null != _inMemoryCacheEntryCount) {
            if (max != _maxInMemoryCacheEntryCount.getCount() && _inMemoryCacheEntryCount.getCount() != current)
                Tr.debug(tc, methodName + " cacheName=" + _sCacheName + " max=" + max + " current=" + current + " enable=" + this._enable, this);
        }

        if (_enable) {
            if (_maxInMemoryCacheEntryCount != null)
                _maxInMemoryCacheEntryCount.setCount(max);

            if (_inMemoryCacheEntryCount != null)
                _inMemoryCacheEntryCount.setCount(current);
        }
    }
199880
def enable_cache(self):
        """"""
        self.set_header('Cache-Control', 'max-age=%d, public' % CACHE_TIME)

        d = datetime.datetime.now() + datetime.timedelta(seconds=CACHE_TIME)
        self.set_header('Expires', d.strftime('%a, %d %b %Y %H:%M:%S'))

        self.set_header('access-control-max-age', CACHE_TIME)
1100227
def set_timeout(self, timeout=None, code=None):
        
        if timeout is None:
            timeout = self.args.timeout if self.args.timeout else 10
        if code is None:
            code = UNKNOWN
        self._timeout_delay = timeout
        self._timeout_code = code
        signal.signal(signal.SIGALRM, self._timeout_handler)
        signal.alarm(timeout)