Skip to content

Commit 597f5e2

Browse files
committed
EhCache3 example updated with disk storage as cache
1 parent 4d1c261 commit 597f5e2

File tree

6 files changed

+83
-4
lines changed

6 files changed

+83
-4
lines changed

.gitignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,3 +36,7 @@ bin
3636
.vagrant
3737
.docker
3838
*.retry
39+
40+
41+
# Cache
42+
jcs_swap

pom.xml

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,12 @@
9292
<version>2.4.3</version>
9393
</dependency>
9494

95-
95+
<!-- https://mvnrepository.com/artifact/com.googlecode.json-simple/json-simple -->
96+
<dependency>
97+
<groupId>com.googlecode.json-simple</groupId>
98+
<artifactId>json-simple</artifactId>
99+
<version>1.1.1</version>
100+
</dependency>
96101

97102

98103
</dependencies>

src/main/java/com/eprogrammerz/examples/cache/example/ehcahce3/ObjectCacheManager.java

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,25 @@ public ObjectCacheManager() {
2828
objectCache = cacheManager.getCache("myCache", String.class, City.class);
2929
}
3030

31+
/*//setting up cache
32+
@PostConstruct
33+
public void setUp(){
34+
CacheManager cacheManager = CacheManagerBuilder.newCacheManagerBuilder()
35+
// .with(new CacheManagerPersistenceConfiguration(new File(getCacheStoragePath(), "cachedData")))
36+
.withCache("jsonCache",
37+
CacheConfigurationBuilder.newCacheConfigurationBuilder(String.class, JsonObjectWrapper.class,
38+
ResourcePoolsBuilder.newResourcePoolsBuilder()
39+
.heap(20, EntryUnit.ENTRIES)
40+
.offheap(10, MemoryUnit.MB))
41+
// .disk(20L, MemoryUnit.MB))
42+
.withExpiry(Expirations.timeToLiveExpiration(Duration.INFINITE))
43+
.withValueSerializingCopier()
44+
.build())
45+
.build(true);
46+
47+
this.objectCache = cacheManager.getCache("jsonCache", String.class, JsonObjectWrapper.class);
48+
}*/
49+
3150
public void putInCache(String key, City value){
3251
try{
3352
objectCache.put(key, value);
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
package com.eprogrammerz.examples.general.jsonparse;
2+
3+
import org.json.simple.JSONArray;
4+
import org.json.simple.parser.JSONParser;
5+
import org.json.simple.parser.ParseException;
6+
7+
/**
8+
* Created by 542596 on 1/23/2017.
9+
*/
10+
public class JsonParseExample {
11+
public static void main(String[] args) {
12+
JSONParser parser = new JSONParser();
13+
String s = "[{\"6\":7},{\"1\":{\"2\":{\"3\":{\"4\":[5,{\"6\":7}]}}}}]";
14+
15+
Object obj = null;
16+
try {
17+
obj = parser.parse(s);
18+
} catch (ParseException e) {
19+
e.printStackTrace();
20+
}
21+
JSONArray array = (JSONArray)obj;
22+
System.out.println(obj);
23+
System.out.println(array);
24+
}
25+
}

src/main/java/com/eprogrammerz/examples/general/regexexample/RegexExample.java

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import java.util.Arrays;
55
import java.util.List;
66
import java.util.Optional;
7+
import java.util.stream.Collectors;
78

89
/**
910
* Created by 542596 on 12/8/2016.
@@ -27,6 +28,12 @@ public static void main(String[] args) {
2728
System.out.println(typeSubtypeId[0] + typeSubtypeId[1]);
2829

2930
String[] splitted = "all-meal".split("\\.");
30-
System.out.println(splitted[1]);
31+
System.out.println(splitted[0]);
32+
33+
String newAwesomeString = "a, b,c, d";
34+
List<String> splittedString = Arrays.asList(newAwesomeString.split(","));
35+
System.out.println(splittedString);
36+
List<String> trimmed = splittedString.stream().map(s -> s.trim()).collect(Collectors.toList());
37+
System.out.println(trimmed);
3138
}
3239
}

src/main/java/com/eprogrammerz/examples/java8/features/StreamExample.java

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
package com.eprogrammerz.examples.java8.features;
22

3-
import java.util.Arrays;
4-
import java.util.List;
3+
import java.util.*;
54
import java.util.stream.Collectors;
65

76
/**
@@ -18,6 +17,26 @@ public static void main(String[] args) {
1817

1918
int emptyStringCount = (int)strings.stream().filter(string -> string.trim().isEmpty()).count();
2019
System.out.println("Empty Strings: "+emptyStringCount);
20+
/*
21+
//This causes NullPointerException
22+
List<Object> nullList = null;
23+
nullList.stream().findFirst().get();
24+
*/
2125

26+
Optional<String> stringOptional = strings.stream().filter(s -> s.length() == 9).findFirst();
27+
System.out.println(stringOptional);
28+
29+
Map<String, Object> sampleMap = new HashMap<>();
30+
String value = (String) sampleMap.get("name");
31+
System.out.println(value);
32+
33+
List<String> stringList = new ArrayList<>();
34+
stringList.add("ogen");
35+
stringList.add(0, "Rai");
36+
System.out.println(stringList);
37+
String valueRemvoed = stringList.remove(0);
38+
System.out.println(valueRemvoed);
39+
stringList.add(0,"Yogen");
40+
System.out.println(stringList);
2241
}
2342
}

0 commit comments

Comments
 (0)