@Override public void record(long key) { Object value = cache.get(key); if (value == null) { if (cache.size() == cache.getMaxSize()) { policyStats.recordEviction(); } cache.put(key, key); policyStats.recordMiss(); } else { policyStats.recordHit(); } }
/** * @see #put(Object, Object, ExpirationPolicy, long, TimeUnit) */ public V put(K key, V value, long duration, TimeUnit timeUnit) { return put(key, value, expirationPolicy.get(), duration, timeUnit); }
/** * @see #put(Object, Object, ExpirationPolicy, long, TimeUnit) */ public V put(K key, V value, long duration, TimeUnit timeUnit) { return put(key, value, expirationPolicy.get(), duration, timeUnit); }
/** * @see #put(Object, Object, ExpirationPolicy, long, TimeUnit) */ public V put(K key, V value, long duration, TimeUnit timeUnit) { return put(key, value, expirationPolicy.get(), duration, timeUnit); }
/** * @see #put(Object, Object, ExpirationPolicy, long, TimeUnit) */ public V put(K key, V value, ExpirationPolicy expirationPolicy) { return put(key, value, expirationPolicy, expirationNanos.get(), TimeUnit.NANOSECONDS); }
/** * @see #put(Object, Object, ExpirationPolicy, long, TimeUnit) */ public V put(K key, V value, ExpirationPolicy expirationPolicy) { return put(key, value, expirationPolicy, expirationNanos.get(), TimeUnit.NANOSECONDS); }
/** * @see #put(Object, Object, ExpirationPolicy, long, TimeUnit) */ public V put(K key, V value, ExpirationPolicy expirationPolicy) { return put(key, value, expirationPolicy, expirationNanos.get(), TimeUnit.NANOSECONDS); }
void putLocalCache(long ttlSeconds) { logger.debug("put local {} = {} with expiration {} seconds", valueKey, this.value, ttlSeconds); CachedValueWrapper valueWrapper = new CachedValueWrapper(this.value, redisCacheAnn, logger); localCache.put(valueKey, valueWrapper, CREATED, ttlSeconds, TimeUnit.SECONDS); }
private ConcurrentMap<String, Long> getMap(String key, int longestDuration) { // Currently unable to putIfAbsent when using jodah's expiry map so will wrap in a lock return lockManager.executeLocked(key, () -> { ConcurrentMap<String, Long> keyMap = expiringKeyMap.get(key); if (keyMap == null) { keyMap = new ConcurrentHashMap<>(); expiringKeyMap.put(key, keyMap, ExpirationPolicy.CREATED, longestDuration, TimeUnit.SECONDS); } return keyMap; }); }
@Override public void expired(String key, Message value) { if(isNullOrEmpty(key)) { return; } if(Objects.isNull(value)) { return; } String appId = value.applicationId; Set<String> appMessages = messagesByApplication.getOrDefault(appId, Sets.create()); appMessages.remove(key); messagesByApplication.put(appId, appMessages); }
@Override public void expired(String key, Message value) { if(isNullOrEmpty(key)) { return; } if(Objects.isNull(value)) { return; } String appId = value.applicationId; Set<String> appMessages = messagesByApplication.getOrDefault(appId, Sets.create()); appMessages.remove(key); messagesByApplication.put(appId, appMessages); }
private MappedAccessToken mapToSelfToken(String clientAt){ MappedAccessToken token=tokenMappings.get(clientAt); if(token != null){ if(token.isExpired()){ AccessToken at=refreshAccessToken(token); token=new MappedAccessToken(clientAt, at); tokenMappings.put(clientAt, token); } return token; } token=newAccessToken(clientAt); if(token!=null){ tokenMappings.put(clientAt, token); } return token; }
@Override public void saveApplication(Application application) throws TException { checkThat(application) .throwing(InvalidArgumentException.class) .is(validApplication()); String applicationId = application.applicationId; mainTable.put(applicationId, application); recents.put(applicationId, application); if (!isNullOrEmpty(application.organizationId)) { Set<Application> applications = applicationsByOrg.getOrDefault(applicationId, Sets.create()); applications.add(application); applicationsByOrg.put(applicationId, applications); } }
@Override public void saveApplication(Application application) throws TException { checkThat(application) .throwing(InvalidArgumentException.class) .is(validApplication()); String applicationId = application.applicationId; mainTable.put(applicationId, application); recents.put(applicationId, application); if (!isNullOrEmpty(application.organizationId)) { Set<Application> applications = applicationsByOrg.getOrDefault(applicationId, Sets.create()); applications.add(application); applicationsByOrg.put(applicationId, applications); } }
@Override public void saveMessage(Message message, LengthOfTime lifetime) throws TException { checkThat(message) .throwing(InvalidArgumentException.class) .is(validMessage()); checkThat(lifetime) .usingMessage("lifetime cannot be missing") .throwing(InvalidArgumentException.class) .is(notNull()); long seconds = TimeFunctions.toSeconds(lifetime); String msgId = message.messageId; messages.put(msgId, message, seconds, TimeUnit.SECONDS); String appId = message.applicationId; Set<String> existing = messagesByApplication.getOrDefault(appId, Sets.create()); existing.add(msgId); messagesByApplication.put(appId, existing); }
@Override public void deleteMessage(String applicationId, String messageId) throws TException { checkThat(applicationId, messageId) .throwing(InvalidArgumentException.class) .are(nonEmptyString()); if (!messages.containsKey(messageId)) { return; } Message message = messages.remove(messageId); String appId = message.applicationId; Set<String> appMessages = messagesByApplication.getOrDefault(appId, Sets.create()); appMessages.remove(messageId); messagesByApplication.put(appId, appMessages); }
@Override public void record(long key) { Object value = cache.get(key); if (value == null) { if (cache.size() == cache.getMaxSize()) { policyStats.recordEviction(); } cache.put(key, key); policyStats.recordMiss(); } else { policyStats.recordHit(); } }
@Override public void deleteMessage(String applicationId, String messageId) throws TException { checkThat(applicationId, messageId) .throwing(InvalidArgumentException.class) .are(nonEmptyString()); if (!messages.containsKey(messageId)) { return; } Message message = messages.remove(messageId); String appId = message.applicationId; Set<String> appMessages = messagesByApplication.getOrDefault(appId, Sets.create()); appMessages.remove(messageId); messagesByApplication.put(appId, appMessages); }
public AccessToken refreshAccessToken(AccessToken old) { if(old instanceof MappedAccessToken) { tokenMappings.remove(((MappedAccessToken) old).getRawToken()); } if (null == config.getTokenUrl()) { throw new IllegalStateException("The tokenUrl must be configured"); } HttpRequest request = httpClient.request(config.getTokenUrl()).addFormParam("grant_type", "refresh_token") .addFormParam("refresh_token", old.getRefreshToken()).setMethod(HTTP.Method.POST); AccessToken newAt= fetchAccessToken(request); if(old instanceof MappedAccessToken){ MappedAccessToken mapped=new MappedAccessToken(((MappedAccessToken)old).getRawToken(), newAt); tokenMappings.put(mapped.getRawToken(), mapped); newAt=mapped; } return newAt; }