@@ -10,7 +10,7 @@ The library is hosted on jcenter. To use it, add the following to your module le
1010
1111``` gradle
1212dependencies {
13- implementation 'com.github.pcpl2:simplecache:1.0 .0'
13+ implementation 'com.github.pcpl2:simplecache:1.1 .0'
1414}
1515```
1616
@@ -31,74 +31,84 @@ val cacheManager = CacheManager.createInstance(appContext, "filesCache")
3131The ` cacheManager ` instance usage cache with file name ` filesCache ` .
3232
3333
34- ## Add elements to cache:
35- The ` add ` function accepts 3 parameters: ` key: Stirng, value: Any, lifetime: Long ` .
34+ ## Add or update elements to cache:
35+ The ` set ` function accepts 3 parameters: ` key: Stirng, value: Any, lifetime: Long ` .
3636
3737The lifetime parameter is the lifetime in seconds and is optional, default setted to 0 (no lifetime).
3838
39- ** To add element to cache instance with set lifetime:**
39+ ** To add or update element to cache instance with set lifetime:**
4040
4141``` kotlin
42- cacheManager.add (" HelloWorldKey" , " Hello World" , 60 )
43- cacheManager.add (" IntValueKey" , 255 , 30 )
44- cacheManager.add (" BooleanKey" , false , 60 )
45- cacheManager.add (" FloatKey" , 5.55 , 60 )
42+ cacheManager.set (" HelloWorldKey" , " Hello World" , 60 )
43+ cacheManager.set (" IntValueKey" , 255 , 30 )
44+ cacheManager.set (" BooleanKey" , false , 60 )
45+ cacheManager.set (" FloatKey" , 5.55 , 60 )
4646```
4747
48- ** To add element to cache instance without set lifetime:**
48+ ** To add or update element to cache instance without set lifetime:**
4949
5050``` kotlin
51- cacheManager.add (" HelloWorldKey" , " Hello World" )
52- cacheManager.add (" IntValueKey" , 255 )
53- cacheManager.add (" BooleanKey" , false )
54- cacheManager.add (" FloatKey" , 5.55 )
51+ cacheManager.set (" HelloWorldKey" , " Hello World" )
52+ cacheManager.set (" IntValueKey" , 255 )
53+ cacheManager.set (" BooleanKey" , false )
54+ cacheManager.set (" FloatKey" , 5.55 )
5555```
5656
5757## Getting element from cache:
58- The ` get ` function accepts 3 parameters: ` key: Stirng, checkExpired: Any, callback : (value: Any? , type: Class<*>? ) -> Unit ` .
58+ The ` get ` function accepts 4 parameters: ` key: Stirng, checkExpired: Boolean = true, success : (value: Any, type: Class<*>) -> Unit, error: (() -> Unit)? = null ` .
5959
6060The checkExpired parameter is optional, default setted as true.
6161
62- In lambda callback ` value ` is a nullable any object and ` type ` is a nullable java Class.
62+ Callback success return value from map and value type.
63+
64+ Callback error is optional and run if element with key not exist or lifetime of element is ended.
6365
6466** To get element from cache instance with lifetime check:**
6567
6668``` kotlin
67- cacheManager.get(" HelloWorldKey" ) { value, type ->
68- System .out .println (value.toString())
69- }
70-
71- cacheManager.get(" IntValueKey" ) { value, type ->
72- System .out .println (value.toString())
73- }
74-
75- cacheManager.get(" BooleanKey" ) { value, type ->
76- System .out .println (value.toString())
77- }
78-
79- cacheManager.get(" FloatKey" ) { value, type ->
80- System .out .println (value.toString())
81- }
69+ cacheManager.get(key = " HelloWorldKey" , success = { value, type ->
70+ Log .d(" simpleCacheLog" , value.toString())
71+ })
72+
73+ cacheManager.get(key = " IntValueKey" , success = { value, type ->
74+ Log .d(" simpleCacheLog" , value.toString())
75+ })
76+
77+ cacheManager.get(key = " BooleanKey" , success = { value, type ->
78+ Log .d(" simpleCacheLog" , value.toString())
79+ }, error = {
80+ Log .d(" simpleCacheLog" , " BooleanKey is empty." )
81+ })
82+
83+ cacheManager.get(key = " FloatKey" , success = { value, type ->
84+ Log .d(" simpleCacheLog" , value.toString())
85+ }, error = {
86+ Log .d(" simpleCacheLog" , " FloatKey is empty." )
87+ })
8288```
8389
8490** To get element from cache instance without lifetime check:**
8591
8692``` kotlin
87- cacheManager.get(" HelloWorldKey" , false ) { value, type ->
88- System .out .println (value.toString())
89- }
90-
91- cacheManager.get(" IntValueKey" , false ) { value, type ->
92- System .out .println (value.toString())
93- }
94-
95- cacheManager.get(" BooleanKey" , false ) { value, type ->
96- System .out .println (value.toString())
97- }
98-
99- cacheManager.get(" FloatKey" , false ) { value, type ->
100- System .out .println (value.toString())
101- }
93+ cacheManager.get(key = " HelloWorldKey" , checkExpired = false , success = { value, type ->
94+ Log .d(" simpleCacheLog" , value.toString())
95+ })
96+
97+ cacheManager.get(key = " IntValueKey" , checkExpired = false , success = { value, type ->
98+ Log .d(" simpleCacheLog" , value.toString())
99+ })
100+
101+ cacheManager.get(key = " BooleanKey" , checkExpired = false , success = { value, type ->
102+ Log .d(" simpleCacheLog" , value.toString())
103+ }, error = {
104+ Log .d(" simpleCacheLog" , " BooleanKey is empty." )
105+ })
106+
107+ cacheManager.get(key = " FloatKey" , checkExpired = false , success = { value, type ->
108+ Log .d(" simpleCacheLog" , value.toString())
109+ }, error = {
110+ Log .d(" simpleCacheLog" , " FloatKey is empty." )
111+ })
102112```
103113
104114## Remove element from cache
@@ -113,7 +123,7 @@ cacheManager.remove("FloatKey")
113123## Clear cache instance
114124The ` removeAllElements ` function cleans the entire cache.
115125
116- ** To clear cachce istance:**
126+ ** To clear cahce istance:**
117127
118128``` kotlin
119129cacheManager.removeAllElements()
0 commit comments