File tree 5 files changed +17
-15
lines changed
caching/src/main/java/com/iluwatar/caching
5 files changed +17
-15
lines changed Original file line number Diff line number Diff line change @@ -85,13 +85,14 @@ public static void main(final String[] args) {
85
85
// installed and socket connection is open).
86
86
App app = new App (isDbMongo (args ));
87
87
app .useReadAndWriteThroughStrategy ();
88
- System .out .println ("==============================================" );
88
+ String splitLine = "==============================================" ;
89
+ LOGGER .info (splitLine );
89
90
app .useReadThroughAndWriteAroundStrategy ();
90
- System . out . println ( "==============================================" );
91
+ LOGGER . info ( splitLine );
91
92
app .useReadThroughAndWriteBehindStrategy ();
92
- System . out . println ( "==============================================" );
93
+ LOGGER . info ( splitLine );
93
94
app .useCacheAsideStategy ();
94
- System . out . println ( "==============================================" );
95
+ LOGGER . info ( splitLine );
95
96
}
96
97
97
98
/**
Original file line number Diff line number Diff line change 26
26
import java .util .Optional ;
27
27
28
28
import com .iluwatar .caching .database .DbManager ;
29
+ import lombok .Data ;
29
30
import lombok .extern .slf4j .Slf4j ;
30
31
31
32
/**
37
38
* appropriate function in the CacheStore class.
38
39
*/
39
40
@ Slf4j
41
+ @ Data
40
42
public class AppManager {
41
43
/**
42
44
* Caching Policy.
43
45
*/
44
- private static CachingPolicy cachingPolicy ;
46
+ private CachingPolicy cachingPolicy ;
45
47
/**
46
48
* Database Manager.
47
49
*/
Original file line number Diff line number Diff line change @@ -43,11 +43,11 @@ public class CacheStore {
43
43
/**
44
44
* Lru cache see {@link LruCache}.
45
45
*/
46
- private static LruCache cache ;
46
+ private LruCache cache ;
47
47
/**
48
48
* DbManager.
49
49
*/
50
- private DbManager dbManager ;
50
+ private final DbManager dbManager ;
51
51
52
52
/**
53
53
* Cache Store.
Original file line number Diff line number Diff line change @@ -45,7 +45,7 @@ public UserAccount readFromDb(final String userId) {
45
45
var iterable = db
46
46
.getCollection (CachingConstants .USER_ACCOUNT )
47
47
.find (new Document (USER_ID , userId ));
48
- if (iterable == null ) {
48
+ if (iterable . first ()== null ) {
49
49
return null ;
50
50
}
51
51
Document doc = iterable .first ();
Original file line number Diff line number Diff line change @@ -13,14 +13,14 @@ public class VirtualDb implements DbManager {
13
13
/**
14
14
* Virtual DataBase.
15
15
*/
16
- private Map <String , UserAccount > virtualDB ;
16
+ private Map <String , UserAccount > db ;
17
17
18
18
/**
19
19
* Creates new HashMap.
20
20
*/
21
21
@ Override
22
22
public void connect () {
23
- virtualDB = new HashMap <>();
23
+ db = new HashMap <>();
24
24
}
25
25
26
26
/**
@@ -30,8 +30,8 @@ public void connect() {
30
30
*/
31
31
@ Override
32
32
public UserAccount readFromDb (final String userId ) {
33
- if (virtualDB .containsKey (userId )) {
34
- return virtualDB .get (userId );
33
+ if (db .containsKey (userId )) {
34
+ return db .get (userId );
35
35
}
36
36
return null ;
37
37
}
@@ -43,7 +43,7 @@ public UserAccount readFromDb(final String userId) {
43
43
*/
44
44
@ Override
45
45
public UserAccount writeToDb (final UserAccount userAccount ) {
46
- virtualDB .put (userAccount .getUserId (), userAccount );
46
+ db .put (userAccount .getUserId (), userAccount );
47
47
return userAccount ;
48
48
}
49
49
@@ -54,8 +54,7 @@ public UserAccount writeToDb(final UserAccount userAccount) {
54
54
*/
55
55
@ Override
56
56
public UserAccount updateDb (final UserAccount userAccount ) {
57
- virtualDB .put (userAccount .getUserId (), userAccount );
58
- return userAccount ;
57
+ return writeToDb (userAccount );
59
58
}
60
59
61
60
/**
You can’t perform that action at this time.
0 commit comments