Last active
October 8, 2015 05:59
-
-
Save marsyang1/297db0853f360c78e725 to your computer and use it in GitHub Desktop.
CacheLoader
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class TestCacheLoader extends CacheLoader<String, Boolean> { | |
@Autowired | |
private AuthUserManager userManager; | |
@Override | |
public AuthUser load(String key) throws Exception { | |
return userManager.getUser(key); | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@Component | |
public class TwoFactorCodeManager { | |
@Autowired | |
private TwoFactorCacheLoader cacheLoader; | |
private LoadingCache<String, Boolean> hasLinkList; | |
@PostConstruct | |
void init() { | |
hasLinkList = CacheBuilder.newBuilder() | |
.maximumSize(100) | |
.expireAfterWrite(1, TimeUnit.HOURS) | |
.build(cacheLoader); | |
} | |
public boolean hasLink(String userId) throws ExecutionException { | |
return hasLinkList.get(userId); | |
} | |
public void remove(String userId) { | |
hasLinkList.invalidate(userId); | |
} | |
public void removeAll() { | |
hasLinkList.invalidateAll(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment