Fix Logs
This commit is contained in:
parent
399ad53b09
commit
a437f5b2eb
@ -69,11 +69,10 @@ import lombok.extern.slf4j.Slf4j;
|
|||||||
@Slf4j
|
@Slf4j
|
||||||
public class App {
|
public class App {
|
||||||
private static final String USE_MONGO_DB = "--mongo";
|
private static final String USE_MONGO_DB = "--mongo";
|
||||||
private DbManager dbManager;
|
|
||||||
private AppManager appManager;
|
private AppManager appManager;
|
||||||
|
|
||||||
public App(boolean isMongo) {
|
public App(boolean isMongo) {
|
||||||
dbManager = DbManagerFactory.initDb(isMongo);
|
DbManager dbManager = DbManagerFactory.initDb(isMongo);
|
||||||
appManager = new AppManager(dbManager);
|
appManager = new AppManager(dbManager);
|
||||||
appManager.initDb();
|
appManager.initDb();
|
||||||
}
|
}
|
||||||
@ -90,9 +89,13 @@ public class App {
|
|||||||
// installed and socket connection is open).
|
// installed and socket connection is open).
|
||||||
App app = new App(isDbMongo(args));
|
App app = new App(isDbMongo(args));
|
||||||
app.useReadAndWriteThroughStrategy();
|
app.useReadAndWriteThroughStrategy();
|
||||||
|
System.out.println("=====================================================");
|
||||||
app.useReadThroughAndWriteAroundStrategy();
|
app.useReadThroughAndWriteAroundStrategy();
|
||||||
|
System.out.println("=====================================================");
|
||||||
app.useReadThroughAndWriteBehindStrategy();
|
app.useReadThroughAndWriteBehindStrategy();
|
||||||
|
System.out.println("=====================================================");
|
||||||
app.useCacheAsideStategy();
|
app.useCacheAsideStategy();
|
||||||
|
System.out.println("=====================================================");
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -71,6 +71,7 @@ public class AppManager {
|
|||||||
* Find user account.
|
* Find user account.
|
||||||
*/
|
*/
|
||||||
public UserAccount find(String userId) {
|
public UserAccount find(String userId) {
|
||||||
|
LOGGER.info("Trying to find {} in cache", userId);
|
||||||
if (cachingPolicy == CachingPolicy.THROUGH || cachingPolicy == CachingPolicy.AROUND) {
|
if (cachingPolicy == CachingPolicy.THROUGH || cachingPolicy == CachingPolicy.AROUND) {
|
||||||
return cacheStore.readThrough(userId);
|
return cacheStore.readThrough(userId);
|
||||||
} else if (cachingPolicy == CachingPolicy.BEHIND) {
|
} else if (cachingPolicy == CachingPolicy.BEHIND) {
|
||||||
@ -85,6 +86,7 @@ public class AppManager {
|
|||||||
* Save user account.
|
* Save user account.
|
||||||
*/
|
*/
|
||||||
public void save(UserAccount userAccount) {
|
public void save(UserAccount userAccount) {
|
||||||
|
LOGGER.info("Save record!");
|
||||||
if (cachingPolicy == CachingPolicy.THROUGH) {
|
if (cachingPolicy == CachingPolicy.THROUGH) {
|
||||||
cacheStore.writeThrough(userAccount);
|
cacheStore.writeThrough(userAccount);
|
||||||
} else if (cachingPolicy == CachingPolicy.AROUND) {
|
} else if (cachingPolicy == CachingPolicy.AROUND) {
|
||||||
|
@ -61,10 +61,10 @@ public class CacheStore {
|
|||||||
*/
|
*/
|
||||||
public UserAccount readThrough(String userId) {
|
public UserAccount readThrough(String userId) {
|
||||||
if (cache.contains(userId)) {
|
if (cache.contains(userId)) {
|
||||||
LOGGER.info("# Cache Hit!");
|
LOGGER.info("# Found in Cache!");
|
||||||
return cache.get(userId);
|
return cache.get(userId);
|
||||||
}
|
}
|
||||||
LOGGER.info("# Cache Miss!");
|
LOGGER.info("# Not found in cache! Go to DB!!");
|
||||||
UserAccount userAccount = dbManager.readFromDb(userId);
|
UserAccount userAccount = dbManager.readFromDb(userId);
|
||||||
cache.set(userId, userAccount);
|
cache.set(userId, userAccount);
|
||||||
return userAccount;
|
return userAccount;
|
||||||
@ -100,10 +100,10 @@ public class CacheStore {
|
|||||||
*/
|
*/
|
||||||
public UserAccount readThroughWithWriteBackPolicy(String userId) {
|
public UserAccount readThroughWithWriteBackPolicy(String userId) {
|
||||||
if (cache.contains(userId)) {
|
if (cache.contains(userId)) {
|
||||||
LOGGER.info("# Cache Hit!");
|
LOGGER.info("# Found in cache!");
|
||||||
return cache.get(userId);
|
return cache.get(userId);
|
||||||
}
|
}
|
||||||
LOGGER.info("# Cache Miss!");
|
LOGGER.info("# Not found in Cache!");
|
||||||
UserAccount userAccount = dbManager.readFromDb(userId);
|
UserAccount userAccount = dbManager.readFromDb(userId);
|
||||||
if (cache.isFull()) {
|
if (cache.isFull()) {
|
||||||
LOGGER.info("# Cache is FULL! Writing LRU data to DB...");
|
LOGGER.info("# Cache is FULL! Writing LRU data to DB...");
|
||||||
@ -155,7 +155,7 @@ public class CacheStore {
|
|||||||
.orElse(List.of())
|
.orElse(List.of())
|
||||||
.stream()
|
.stream()
|
||||||
.map(userAccount -> userAccount.toString() + "\n")
|
.map(userAccount -> userAccount.toString() + "\n")
|
||||||
.collect(Collectors.joining("", "\n--CACHE CONTENT--\n", "----\n"));
|
.collect(Collectors.joining("", "\n--CACHE CONTENT--\n", "----"));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
Loading…
x
Reference in New Issue
Block a user