Calculates the expiration time of the new state based on this resolvers expiry policy.

@param key cache key
@param existing current state
@param operation operation to apply
@param newValue new state
@return the calculated expiry time
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;
      }
    }
  }
1199908
@Override
    public CompletableFuture<Void> add(Operation operation, Duration timeout) {
        ensureRunning();
        return this.operationProcessor.process(operation);
    }
661174
public CompensatingTransactionOperationExecutor recordOperation(
            Object[] args) {
        if (args == null || args.length != 3) {
            throw new IllegalArgumentException(
                    "Invalid arguments for bind operation");
        }
        Name dn = LdapTransactionUtils.getFirstArgumentAsName(args);
        Object object = args[1];
        Attributes attributes = null;
        if (args[2] != null && !(args[2] instanceof Attributes)) {
            throw new IllegalArgumentException(
                    "Invalid third argument to bind operation");
        } else if (args[2] != null) {
            attributes = (Attributes) args[2];
        }

        Name temporaryName = renamingStrategy.getTemporaryName(dn);

        return new RebindOperationExecutor(ldapOperations, dn, temporaryName,
                object, attributes);
    }
290719
function delExpiry(key, req) {
  var rval = this.getRawKey(key);
  if(rval === undefined || rval.e === undefined) return 0;
  // the code flow ensures we have a valid
  // index into the expiring keys array
  this._ekeys.splice(ArrayIndex.indexOf(key, this._ekeys), 1);
  delete this._expires[key];
  delete rval.e;
  return 1;
}
161164
@Override
    public synchronized Object get(Object key) {
        ValueWrapper valueWrapper = (ValueWrapper) super.get(key);
        if (valueWrapper != null) {
            // Check if value has expired
            long creationTime = valueWrapper.getCreationTime();
            long cacheInterval = valueWrapper.getCacheInterval();
            long currentTime = System.currentTimeMillis();
            if (cacheInterval >= 0 && creationTime + cacheInterval < currentTime) {
                remove(key);
                return null;
            }
            return valueWrapper.getValue();
        } else return null;
    }
947662
private static boolean expiring(Date expiry) {
        long timeRemaining = expiry.getTime() - System.currentTimeMillis();
        return timeRemaining < EXPIRY_TIME_MILLIS;
    }
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);
        }
    }
663257
public static boolean lock(CacheConfigBean cacheConfigBean, String key, Object valueObj, int expireTimeInSecond, long timeOutInSecond) {
        final LockData lockData = LOCK_THREAD_DATA.get();
        if (lockData != null) {
            lockData.getLockCount().incrementAndGet();
            return true;
        }

        long startNano = System.nanoTime();

        // 重试间隔等待时间
        final int retryAwait = (int) timeOutInSecond * 1000 / TRY_NUM;

        int autoIncrementTryNum = 0;
        do {
            autoIncrementTryNum++;

            String result = "nil";
            try (Jedis jedis = Redis.useDataSource(cacheConfigBean).getResource()) {
                if (jedis != null)
                    result = ObjectCacheOperate.set(jedis, key, valueObj, "EX", expireTimeInSecond, "NX");
            } catch (Exception e) {
                LOG.error(e);
            }

            if (!EnvUtil.getEnv().equals(EnvUtil.PRODUCTION))
                LOG.info(String.format("SET %s \"%s\" EX %s NX = result: %s, 第 %s 次尝试", key, valueObj, expireTimeInSecond, result, autoIncrementTryNum));

            if ("OK".equals(result)) {
                LOCK_THREAD_DATA.set(new LockData(key, FormatUtil.formatValue(valueObj)));

                if (!EnvUtil.getEnv().equals(EnvUtil.PRODUCTION)) {
                    long endNano = System.nanoTime();
                    long consumeTime = (endNano - startNano) / 1000000;
                    LOG.info(String.format("key: %s, 分布式加锁, 尝试次数： %s, 累计耗时: %s 纳秒", key, autoIncrementTryNum, consumeTime));
                }

                return true;
            }

            if (!EnvUtil.getEnv().equals(EnvUtil.PRODUCTION))
                LOG.info(String.format("key: %s, 分布式加锁, 目前尝试次数: %s, 暂停: %s 毫秒后继续尝试", key, autoIncrementTryNum, retryAwait));

            LockSupport.parkNanos(TimeUnit.MILLISECONDS.toNanos(retryAwait));

        } while (autoIncrementTryNum < TRY_NUM);

        return false;
    }
1281336
def expireat(self, key, when):
        """"""
        expire_time = datetime.fromtimestamp(when)
        key = self._encode(key)
        if key in self.redis:
            self.timeouts[key] = expire_time
            return True
        return False
817435
public V put(K key, V value)
  {
    Entry<V> oldValue = _cache.put(key, new Entry<V>(_expireInterval, value));

    if (oldValue != null)
      return oldValue.getValue();
    else
      return null;
  }
274535
function (operation, parameter) {
  // TODO the reference to operation.api is not available
  if (operation.api && operation.api.parameterMacro) {
    return operation.api.parameterMacro(operation, parameter);
  } else {
    return parameter.defaultValue;
  }
}
331489
@Override
    public V remove(Object key) {
        CachedValue<K, V> entry = map.remove(key);
        if (entry != null) {
            onValueRemove(entry);
            if (!isValueExpired(entry)) {
                return (V) entry.getValue();
            }
        }
        return null;
    }
467155
public Timestamp getOrAddToCache(Timestamp newValue, boolean hard)
    {
        if (newValue == null || newValue instanceof CachedImmutableTimestamp || newValue == NullDataTimestamp.getInstance())
        {
            return newValue;
        }
        return (Timestamp) weakPool.getIfAbsentPut(newValue, hard);
    }
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
175647
public static <T> T queryTryCache(Class<? extends BaseEntity> entityClass,String key,long expireSeconds,Callable<T> dataCaller){
		
		if(CacheHandler.cacheProvider == null){
			try {
				return dataCaller.call();
			} catch (Exception e) {
				throw new RuntimeException(e);
			}
		}
		
		String entityClassName = entityClass.getSimpleName();
		key = entityClassName + CacheHandler.SPLIT_PONIT + key;
		T result = CacheHandler.cacheProvider.get(key);
		if(result == null){
			try {				
				result = dataCaller.call();
				if(result != null){
					CacheHandler.cacheProvider.set(key, result, expireSeconds);
					String cacheGroupKey = entityClassName + CacheHandler.GROUPKEY_SUFFIX;
					CacheHandler.cacheProvider.putGroup(cacheGroupKey, key, expireSeconds);
				}
			} catch (Exception e) {
				throw new RuntimeException(e);
			}
		}
		return result;
	}
56310
public function _performOperation($key, FieldOperation $operation)
    {
        $oldValue = null;
        if (isset($this->estimatedData[$key]))
        {
            $oldValue = $this->estimatedData[$key];
        }
        $newValue = $operation->_apply($oldValue, $this, $key);
        if ($newValue !== null)
        {
            $this->estimatedData[$key] = $newValue;
        } else if (isset($this->estimatedData[$key]))
        {
            unset($this->estimatedData[$key]);
        }

        if (isset($this->operationSet[$key]))
        {
            $oldOperations = $this->operationSet[$key];
            $newOperations = $operation->_mergeWithPrevious($oldOperations);
            $this->operationSet[$key] = $newOperations;
        } else
        {
            $this->operationSet[$key] = $operation;
        }
        $this->dataAvailability[$key] = true;
    }
515539
public static ExpiryPolicy<Object, Object> timeToIdleExpiration(Duration timeToIdle) {
    Objects.requireNonNull(timeToIdle, "TTI duration cannot be null");
    if (timeToIdle.isNegative()) {
      throw new IllegalArgumentException("TTI duration cannot be negative");
    }
    return new TimeToIdleExpiryPolicy(timeToIdle);
  }