-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathREADME.txt
107 lines (67 loc) · 4.36 KB
/
README.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
Installation
============
The following steps can be skipped if you have already installed the following libraries:
1. Java Development Kit version 1.7 or greater.
2. Maven software project management tool version 3.0 or greater.
3. Make sure that you can execute the following two commands:
java --versoin
mvn
If that doesn't work, then please revisit the steps in either 1 or 2 accordingly.
3. Unzip the file into a directory.
4. Open up a command prompt and change to the directory where the files were unzipped.
5. Type the following command in the console:
mvn package
Maven will perform the following operations:
- Download the required jar files from the Maven repository to your <home directory>/.m2
- Compile the source codes
- Run the JUnit tests
- Package the .class files into a jar named "lenspot-cache-0.0.1-SNAPSHOT.jar"
6. Check if the jar file can be located in ./target
Sample Run
==========
You can view the example in the /src/test/java/com/lenspot/devtools/cache/impl/CacheTest.java directory.
The sample creates an instance of cache object, set a value to the cache and retrieve it back.
You can run the example by issuing the following command:
mvn exec:java -Dexec.mainClass="com.lenspot.devtools.cache.sample.CacheExample" -Dexec.args="foo bar"
The above sample run uses "foo" as the key and "bar" as the value.
Here is a sample output:
INFO [com.lenspot.devtools.cache.sample.CacheExample.main()] (CacheExample.java:25) - Got your input:
INFO [com.lenspot.devtools.cache.sample.CacheExample.main()] (CacheExample.java:26) - Key: foo
INFO [com.lenspot.devtools.cache.sample.CacheExample.main()] (CacheExample.java:27) - Value: bar
INFO [com.lenspot.devtools.cache.sample.CacheExample.main()] (CacheExample.java:28) - Setting the value to cache.
INFO [com.lenspot.devtools.cache.sample.CacheExample.main()] (CacheExample.java:30) - Retrieved back your value from the cache: bar
Object Instantiation
====================
Instantiate a Cache object from the CacheFactory class:
int numSets = 100;
int numBlocks = 4;
Cache<String, String> cache = new CacheFactory<String, String>()
.createNWaySetAssociatedCacheUsingLRU(numSets, numBlocks);
There are two parameters for cache size allocation:
1. The number of cache sets - This parameter controls the maximum number of cache sets can be allocated for a set associated cache.
2. The number of cache blocks - This parameter controls the maximum number of cache blocks can be allocated per each cache set.
User-defined Algorithm
======================
A developer can provide customized implementation for the cache algorithm through the Java interface com.lenspot.devtools.cache.CacheAlgorithm.
Please refer to the default implementations LRUCacheAlhorithm.java and MRUCacheAlgorithm.java.
Use the following method in CacheFactory.java to instantiate a cache object using customized algorithm:
public static <K, V> Cache<K, V> createNWaySetAssociatedCache(int numSets, int numBlocks, CacheAlgorithm<K, V> algorithm);
Multi-threaded Environment
==========================
The library has been tested in a multithreaded environment, please refer to the test MutiThreadingTest.java
The test will also log some statistics about the use of the cache in the test, here is a sample output from the test:
INFO [main] (MultithreadingTest.java:107) - Number of sample key/value pairs = 100
INFO [main] (MultithreadingTest.java:108) - Total consumers = 100
INFO [main] (MultithreadingTest.java:109) - Number of cache sets = 4
INFO [main] (MultithreadingTest.java:110) - Number of cache blocks/set = 10
INFO [main] (MultithreadingTest.java:111) - Total Hits = 5903615
INFO [main] (MultithreadingTest.java:112) - Total Miss = 9275426
INFO [main] (MultithreadingTest.java:113) - Total Hit % = 38.89
INFO [main] (MultithreadingTest.java:114) - Hits mean = 59036.15
INFO [main] (MultithreadingTest.java:115) - Hits stdev = 1778.21
INFO [main] (MultithreadingTest.java:116) - Miss mean = 92754.26
INFO [main] (MultithreadingTest.java:117) - Miss stdev = 2760.19
You can play around with the parameters in the MutiThreadingTest.java later on if you would like to see how multi-threading program make use of the cache. There also a few other JUnit tests which you can explore.
Java Doc
========
Java Docs can be generated by un-commenting the javadoc section in the pom.xml files.