Skip to content

Commit b0bdaa1

Browse files
author
crypticminds
committed
2 parents 41c5ce4 + ec56af1 commit b0bdaa1

File tree

2 files changed

+9
-31
lines changed

2 files changed

+9
-31
lines changed

README.md

Lines changed: 8 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# ColdStorage
2-
[![License](https://img.shields.io/badge/License-Apache%202.0-blue.svg)](https://opensource.org/licenses/Apache-2.0) ![Downloads](https://jitpack.io/v/crypticminds/ColdStorage/month.svg) [![Codacy Badge](https://api.codacy.com/project/badge/Grade/946075aa2cc14be3af73eb8a9fc2352b)](https://www.codacy.com/manual/crypticminds/ColdStorage?utm_source=github.com&utm_medium=referral&utm_content=crypticminds/ColdStorage&utm_campaign=Badge_Grade) [![Build Status](https://travis-ci.com/crypticminds/ColdStorage.svg?branch=master)](https://travis-ci.com/crypticminds/ColdStorage)
2+
[![License](https://img.shields.io/badge/License-Apache%202.0-blue.svg)](https://opensource.org/licenses/Apache-2.0) ![Downloads](https://jitpack.io/v/crypticminds/ColdStorage/month.svg) [![Codacy Badge](https://api.codacy.com/project/badge/Grade/946075aa2cc14be3af73eb8a9fc2352b)](https://www.codacy.com/manual/crypticminds/ColdStorage?utm_source=github.com&utm_medium=referral&utm_content=crypticminds/ColdStorage&utm_campaign=Badge_Grade) [![Build Status](https://travis-ci.com/crypticminds/ColdStorage.svg?branch=master)](https://travis-ci.com/crypticminds/ColdStorage) [![Gitter](https://badges.gitter.im/ColdStorageCache/community.svg)](https://gitter.im/ColdStorageCache/community?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge)
33

44
**A lightweight caching library for android written in Kotlin.**
55

@@ -92,7 +92,6 @@ By default all data is kept in the disk for upto 2 days.
9292
* enableLoadingAnimation (optional) : To enable an animation like a rotating loading spinner set this to true. This will
9393
only work if a placeholder image has been supplied.
9494

95-
9695
After the image views have been annotated , bind the class where the image views are present using the method
9796
Cache.bind(objectOfClass).
9897

@@ -165,40 +164,18 @@ cacheLayer.makeRemoteCallToServiceB(.... )
165164
```
166165

167166
## @Refrigerate Annotation
168-
Annotate your functions using this to keep the output of the function in the cache for a given set of inputs .
169-
170-
### For releases > 2.1.0
171-
172-
Now you can use @CacheKey annotation to declare parameters as the keys of the cache
167+
Annotate your functions using this to keep the output of the function in the cache for a given set of inputs.
173168

174169
```kotlin
175170
@Refrigerate(timeToLive : 2000, operation = "cacheImage")
176-
fun downloadImage(@CacheKey url : String , @CacheKey someOtherVariable : String , variableThatIsNotAKey : String) : Bitmap {
171+
fun downloadImage(@CacheKey url : String , @CacheKey data : String , variableThatIsNotAKey : String) : Bitmap {
177172
.....
178173
}
179174
```
175+
This will keep the bitmap in the cache for 2 seconds.
180176

181-
### For releases < 2.1.0
182-
183-
If you are using the old version , you will need to use the keys parameter to define your cache keys.
184-
185-
```kotlin
186-
@Refrigerate(timeToLive : 2000, operation = "cacheImage" , keys=["url"])
187-
fun downloadImage(url : String) : Bitmap {
188-
.....
189-
}
190-
```
191-
This will keep the bitmap in the cache for a unique URL for 2 seconds.
192-
The **keys** parameter will decide which parameters of the function will be the key of the cache.
193-
194-
```kotlin
195-
@Refrigerate(timeToLive : 20000, operation = "remoteServiceCall" , keys=["url","data"])
196-
fun callRemoteService(url : String, data : String , someRandomVariable : String) : String {
197-
.....
198-
}
199-
```
200-
In the above example **url** and **data** will together form the key of the cache , such that if it determines that the same url and data is passed to the function (until the value expires in the cache) irrespective of the value of "**someRandomVariable**" it will
201-
return the data from the cache. Using the **keys** parameter you can decide which variables should form the key of the cache for the annotated function.
177+
In the above example **url** and **data** will together form the key of the cache , such that if it determines that the same url and data is passed to the function (until the value expires in the cache) irrespective of the value of "**variableThatIsNotAKey**" it will
178+
return the data from the cache.
202179

203180
During compilation the annotations will generate a class "**GeneratedCacheLayer**
204181
and instead of using your annotated functions directly you will use them via this class.
@@ -211,7 +188,7 @@ To invoke the above functions you will call :-
211188
GeneratedCacheLayer.callRemoteService("myurl", "mydata" , "myrandomVariable" , objectOfTheClassWhereTheMethodBelongs , callback)
212189
```
213190

214-
The generated method will have the same name and accept the same variables as the original method but with two extra parameters , one is the object of the class where the original annotated method is present in and the second is the callback (**OnOperationsuccessfulCallback**) which will be used to pass the cached data to the main thread from the background thread. (All cache operations take place on a separate thread). For more information about the usage check the example below or the [article](https://medium.com/@crypticmindscom_5258/caching-made-easy-in-android-with-kotlin-part-2-61bb476063b4)
191+
The generated method will have the same name and accept the same variables as the original method but with two extra parameters , one is the object of the class where the original annotated method is present in and the second is the callback (**OnOperationsuccessfulCallback**) which will be used to pass the cached data to the main thread from the background thread. (All cache operations take place on a separate thread). Check the [wiki](https://github.com/crypticminds/ColdStorage/wiki/@Refrigerate-annotation) for more details.
215192

216193
> After applying the annotation you can try running your application on AVD so that the GeneratedCacheLayer file is created. Then use it just like
217194
> a regular class in your project. Your IDE will be able to index it
@@ -276,7 +253,7 @@ The generated method will have the same name and accept the same variables as th
276253
}
277254
```
278255

279-
**The update method should return the value to be cahced in form of a string. If you are planning to store complex objects , serialize them into a string and return them from the method.**
256+
**The update method should return the value to be cached in form of a string. If you are planning to store complex objects , serialize them into a string and return them from the method.**
280257

281258
Your cache is now ready. To use the cache create an instance of it and call the **get** method of the cache.
282259

_config.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
theme: jekyll-theme-cayman

0 commit comments

Comments
 (0)