Skip to content

Commit

Permalink
change cache name & unify cache
Browse files Browse the repository at this point in the history
  • Loading branch information
imbajin committed May 20, 2021
1 parent 7d80fd9 commit b167190
Showing 1 changed file with 8 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ public class StandardAuthManager implements AuthManager {
private final HugeGraphParams graph;
private final EventListener eventListener;
private final Cache<Id, HugeUser> usersCache;
private final Cache<Id, String> validateCache;
private final Cache<Id, String> pwdCache;

private final EntityManager<HugeUser> users;
private final EntityManager<HugeGroup> groups;
Expand All @@ -60,8 +60,7 @@ public StandardAuthManager(HugeGraphParams graph) {
this.graph = graph;
this.eventListener = this.listenChanges();
this.usersCache = this.cache("users");
this.validateCache = CacheManager.instance().cache("validate_pwd");
this.validateCache.expire(CACHE_EXPIRE);
this.pwdCache = this.cache("users_pwd");

this.users = new EntityManager<>(this.graph, HugeUser.P.USER,
HugeUser::fromVertex);
Expand All @@ -76,9 +75,9 @@ public StandardAuthManager(HugeGraphParams graph) {
HugeAccess::fromEdge);
}

private Cache<Id, HugeUser> cache(String prefix) {
private <V> Cache<Id, V> cache(String prefix) {
String name = prefix + "-" + this.graph.name();
Cache<Id, HugeUser> cache = CacheManager.instance().cache(name);
Cache<Id, V> cache = CacheManager.instance().cache(name);
cache.expire(CACHE_EXPIRE);
return cache;
}
Expand Down Expand Up @@ -123,7 +122,7 @@ private void initSchemaIfNeeded() {

private void invalidCache() {
this.usersCache.clear();
this.validateCache.clear();
this.pwdCache.clear();
}

@Override
Expand Down Expand Up @@ -349,13 +348,13 @@ public HugeUser matchUser(String name, String password) {
return null;
}

Id id = IdGenerator.of(name);
if (password.equals(validateCache.get(id))) {
Id id = IdGenerator.of(user.id());
if (password.equals(pwdCache.get(id))) {
return user;
}

if (StringEncoding.checkPassword(password, user.password())) {
validateCache.update(id, password);
pwdCache.update(id, password);
return user;
}
return null;
Expand Down

0 comments on commit b167190

Please sign in to comment.