/** Gets a token from the cache if possible. */ public String get(Account account, String tokenType, String packageName, byte[] sigDigest) { Key k = new Key(account, tokenType, packageName, sigDigest); Value v = mCachedTokens.get(k); long currentTime = System.currentTimeMillis(); if (v != null && currentTime < v.expiryEpochMillis) { return v.token; } else if (v != null) { remove(account.type, v.token); } return null; }
/** * Caches the specified token until the specified expiryMillis. The token will be associated with * the given token type, package name, and digest of signatures. * * @param token * @param tokenType * @param packageName * @param sigDigest * @param expiryMillis */ public void put( Account account, String token, String tokenType, String packageName, byte[] sigDigest, long expiryMillis) { Preconditions.checkNotNull(account); if (token == null || System.currentTimeMillis() > expiryMillis) { return; } Key k = new Key(account, tokenType, packageName, sigDigest); Value v = new Value(token, expiryMillis); mCachedTokens.putToken(k, v); }
public void remove(Account account) { mCachedTokens.evict(account); }
/** * Evicts the specified token from the cache. This should be called as part of a token * invalidation workflow. */ public void remove(String accountType, String token) { mCachedTokens.evict(accountType, token); }