opts.act: can be one of 'save/load/remove' opts.key: the key opts.value: the value opts.expire: the cache expiry value
511516
function(opts, callback) {
  if (callback === undefined) {
    throw new Error('callback undefined in $fh.cache. See documentation of $fh.cache for proper usage');
  }

  if (opts.act === undefined) {
    return callback('No cache actions defined!');
  }

  var fullKey = appname + opts.key;

  var client = redisClient();
  if (opts.act === 'save') {
    client.on("connect", function() {
      if (redisPassword) {
        client.auth(redisPassword, function(err) {
          if (err) {
            callback(err);
          }
        });
      }
    });
    client.on("error", function(err) {
      console.error("fh.cache error: %s ", err);
      return callback(err);
    });
    client.on("ready", function(err) {
      if (err) {
        return callback(err);
      }
      if (opts.expire !== undefined) {
        client.setex(fullKey, opts.expire, opts.value, function(err, reply) {
          client.quit();
          return callback(err, reply);
        });
      } else {
        client.set(fullKey, opts.value, function(err, reply) {
          client.quit();
          return callback(err, reply);
        });
      }
    });
  } else if (opts.act === 'load') {
    client.on("connect", function() {
      if (redisPassword) {
        client.auth(redisPassword, function(err) {
          if (err) {
            callback(err);
          }
        });
      }
    });
    client.on("error", function(err) {
      console.error("fh.cache error: %s", err);
      callback(err);
      client.end();
    });
    client.on("ready", function(err) {
      if (err) {
        return callback(err);
      }
      client.get(fullKey, function(err, reply) {
        client.quit();
        return callback(err, reply);
      });
    });
  } else if (opts.act === 'remove') {
    client.on("connect", function() {
      if (redisPassword) {
        client.auth(redisPassword, function(err) {
          if (err) {
            callback(err);
          }
        });
      }
    });
    client.on("error", function(err) {
      console.error("fh.cache error: %s", err);
      return callback(err);
    });
    client.on("ready", function(err) {
      if (err) {
        return callback(err);
      }
      client.del(fullKey, function(err, reply) {
        client.quit();
        return callback(err, reply);
      });
    });
  } else {
    return callback("Unknown cache action: " + opts.act);
  }
}
361999
public void cache(String key, Object obj, int expiration) {
        H.Session session = this.session;
        if (null != session) {
            session.cache(key, obj, expiration);
        } else {
            app().cache().put(key, obj, expiration);
        }
    }
1255273
def get_value(self, merge=True, createfunc=None,
                  expiration_time=None, ignore_expiration=False):
        
        cache, cache_key = self._get_cache_plus_key()

        # ignore_expiration means, if the value is in the cache
        # but is expired, return it anyway.   This doesn't make sense
        # with createfunc, which says, if the value is expired, generate
        # a new value.
        assert not ignore_expiration or not createfunc, \
            "Can't ignore expiration and also provide createfunc"

        if ignore_expiration or not createfunc:
            cached_value = cache.get(cache_key,
                                     expiration_time=expiration_time,
                                     ignore_expiration=ignore_expiration)
        else:
            cached_value = cache.get(cache_key)
            if not cached_value:
                cached_value = createfunc()
                cache.set(cache_key, cached_value, timeout=expiration_time)

        if cached_value and merge:
            cached_value = self.merge_result(cached_value, load=False)

        return cached_value
580263
function(key) {

            // try to fetch expiration time for key
            var expireTime = parseInt(this._storage.getItem(this._expiration_key_prefix + key));

            // if got expiration time return how much left to live
            if (expireTime && !isNaN(expireTime)) {

                return expireTime - this.getTimestamp();
            }

            // if don't have expiration time return null
            return null;
        }
490496
void expireAfterAccess(String key, @Nullable String value) {
    requireArgument(expireAfterAccessDuration == UNSET_INT, "expireAfterAccess was already set");
    expireAfterAccessDuration = parseDuration(key, value);
    expireAfterAccessTimeUnit = parseTimeUnit(key, value);
  }
228210
function get (key) {
  return isExpired(key).then(hasExpired => {
    if (hasExpired) {
      return remove(key).then(() => Promise.resolve(undefined))
    } else {
      return storage.get(`${prefix}${key}`)
    }
  })
}
1149656
function(namespace, key) {
            var ckey = Cache.key(namespace, key);
            var ctime = (new Date()).getTime();

            var v = Storage.get(ckey);
            if (v == null) {
                return null;
            } else {
                if (v.expiration == -1 || v.expiration > ctime) {
                    return v.value;
                } else {
                    Storage.remove(ckey);
                    return null;
                }
            }
        }
442062
def store(self, key, expiry, data):
        
        self.cache.set(key, (expiry, data), self.cache_ttl)

        if getattr(settings, 'CACHEBACK_VERIFY_CACHE_WRITE', True):
            # We verify that the item was cached correctly.  This is to avoid a
            # Memcache problem where some values aren't cached correctly
            # without warning.
            __, cached_data = self.cache.get(key, (None, None))
            if data is not None and cached_data is None:
                raise RuntimeError(
                    "Unable to save data of type %s to cache" % (
                        type(data)))
508275
private long calculateExpiryTime(K key, PutOperation<K, V> existing, Operation<K, V> operation, Result<K, V> newValue) {
    if (operation.isExpiryAvailable()) {
      return operation.expirationTime();
    } else {
      try {
        Duration duration;
        if (existing == null) {
          duration = requireNonNull(expiry.getExpiryForCreation(key, newValue.getValue()));
        } else {
          duration = expiry.getExpiryForUpdate(key, existing::getValue, newValue.getValue());
          if (duration == null) {
            return existing.expirationTime();
          }
        }
        if (duration.isNegative()) {
          duration = Duration.ZERO;
        } else if (isExpiryDurationInfinite(duration)) {
          return Long.MAX_VALUE;
        }
        return ExpiryUtils.getExpirationMillis(operation.timeStamp(), duration);
      } catch (Exception ex) {
        LOG.error("Expiry computation caused an exception - Expiry duration will be 0 ", ex);
        return Long.MIN_VALUE;
      }
    }
  }
773900
function () {
            var cache = this._cache;
            var expirationTime = ((new Date()).getTime() - this._expiresAfter * 1000);

            for (var url in cache) {
                if (cache.hasOwnProperty(url) && cache[url].age < expirationTime) {
                    delete cache[url];
                }
            }
        }
667673
def time_left(self, key):
        
        self._evict_old()

        if key not in self._store:
            raise KeyError("key {0!r} does not exist in cache".format(key))

        return self.timeout - (time.time() - self._store[key][1])
91045
function(key) {

            // remove the item itself and its expiration time
            var ret = this._storage.removeItem(key);
            this._storage.removeItem(this._expiration_key_prefix + key);

            // return optional return code
            return ret;
        }
881783
def expires_at(self):
        
        if 'SignatureExpirationTime' in self._signature.subpackets:
            expd = next(iter(self._signature.subpackets['SignatureExpirationTime'])).expires
            return self.created + expd
        return None
739679
def set(self, key, value, expire_in=None):
    
    if key not in self._keystore:
      self._keystore[key] = InMemoryItemValue(expire_in=expire_in)

    k = self._keystore[key]
    """:type k InMemoryItemValue"""
    k.update_expire_time(expire_in)
    k.value = value
1202885
def expire_key(self, key):
        '''
        
        '''
        value = self.base_dict[key]
        del self[key]
        if self.callback is not None:
            self.callback(
                key, value, *self.callback_args, **self.callback_kwargs)
949313
def set_cache_expiry(response):
    
    if response.cache_control.max_age is None and 'CACHE_DEFAULT_TIMEOUT' in config.cache:
        response.cache_control.max_age = config.cache['CACHE_DEFAULT_TIMEOUT']
    return response
594172
def expire(self, key, timeout):
        
        if isinstance(timeout, float):
            return self.pexpire(key, int(timeout * 1000))
        if not isinstance(timeout, int):
            raise TypeError(
                "timeout argument must be int, not {!r}".format(timeout))
        fut = self.execute(b'EXPIRE', key, timeout)
        return wait_convert(fut, bool)