Skip to content

Commit db9ad6e

Browse files
author
crypticminds
committed
Updating Readme.md
1 parent e1572b8 commit db9ad6e

File tree

1 file changed

+53
-47
lines changed

1 file changed

+53
-47
lines changed

README.md

Lines changed: 53 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,28 @@
1-
# 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)
31

4-
**A lightweight caching library for android written in Kotlin.**
2+
# ColdStorage
3+
<p align="center">
4+
<img src="https://i.imgur.com/rEE8hUO.jpg"/>
5+
</p>
56

6-
![Logo](https://i.imgur.com/rEE8hUO.jpg)
7+
**A lightweight caching library for android**
78

8-
## Usage with annotation
9+
[![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&amp;utm_medium=referral&amp;utm_content=crypticminds/ColdStorage&amp;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)
910

10-
> Check the post for an indepth tutorial on how to use @Refrigerate
11-
> annotation to cache data :-
12-
> <https://medium.com/@crypticmindscom_5258/caching-made-easy-in-android-with-kotlin-part-2-61bb476063b4>
13-
>
14-
> Check out the post for usage of @Freeze annotation
15-
> <https://medium.com/@crypticmindscom_5258/caching-made-easy-on-android-with-kotlin-part-3-3d4cfcb57df0>
16-
>
17-
> Check out the post for usage of @LoadImage annotation
18-
> <https://medium.com/@crypticmindscom_5258/caching-made-easy-on-android-with-kotlin-part-4-18e7b066e9c2>
19-
>
20-
> Examples can be found here :-
21-
> <https://github.com/crypticminds/coldstorageexamples>
11+
# Quicklinks
2212

23-
### For detailed description of each component, usage and examples check the [wiki](https://github.com/crypticminds/ColdStorage/wiki)
13+
* [**Feature requests**](https://github.com/crypticminds/ColdStorage/issues/new?assignees=&labels=&template=feature_request.md&title=): Got a new requirement? Request it here and it will be delivered.
14+
* [**Bugs**](https://github.com/crypticminds/ColdStorage/issues/new?assignees=&labels=&template=bug_report.md&title=): Report a bug here and it will be squashed.
15+
* [**Questions**](https://gitter.im/ColdStorageCache/community?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge): Get your questions about contributing, usage or anything related to the library answered here.
16+
* [**Examples**](https://github.com/crypticminds/coldstorageexamples) : Check out various examples here.
17+
* [**Suggestions/Complaints/Feedbacks**](https://github.com/crypticminds/ColdStorage/issues/new): Got something in your mind regarding this library? Please share and help us improve.
18+
* [**Upcoming features**](https://github.com/crypticminds/ColdStorage/wiki/Upcoming-features) : If you are interested to see all the exciting features lined up for delivery.
2419

25-
## Setup
20+
# Articles
21+
* [Caching in general](https://medium.com/@crypticmindscom_5258/caching-made-easy-with-kotlin-part-1-53433c756978)
22+
* [@Refrigerate annotation usage](https://medium.com/@crypticmindscom_5258/caching-made-easy-in-android-with-kotlin-part-2-61bb476063b4)
23+
* [@Freeze annotation usage](https://medium.com/@crypticmindscom_5258/caching-made-easy-on-android-with-kotlin-part-3-3d4cfcb57df0)
24+
* [@LoadImage anniration usage](https://medium.com/@crypticmindscom_5258/caching-made-easy-on-android-with-kotlin-part-4-18e7b066e9c2)
25+
# Setup
2626

2727
* Add kotlin-kapt gradle plugin to **app build.gradle** file
2828

@@ -36,7 +36,7 @@
3636

3737
***Check the latest release to get the newest features.***
3838

39-
You need to initialize the cache when the application starts. The initialization takes care of pulling previously cached data and loading them into the memory .
39+
**You need to initialize the cache when the application starts. The initialization takes care of pulling previously cached data and loading them into the memory .**
4040

4141
* Create an application class and initialize the cache in the onCreate() method.
4242

@@ -50,9 +50,9 @@
5050
super.onCreate()
5151
Cache.initialize(context = applicationContext)
5252
}
53-
5453
}
5554
```
55+
You can configure the cache with additional parameters such as a global time to live, maximum cache size etc. Refer the [wiki]([https://github.com/crypticminds/ColdStorage/wiki/Initialize-cache](https://github.com/crypticminds/ColdStorage/wiki/Initialize-cache)) for more details.
5656

5757
* Register your application in the android manifest file by providing the **android:name** attribute
5858

@@ -66,8 +66,11 @@
6666
android:theme="@style/AppTheme"
6767
android:name=".application.Application">
6868
</application>
69-
```
70-
## @LoadImage Annotation (BETA)
69+
# Quick guide
70+
71+
### This guide will only provide a basic usage guide. For detailed description of each component, usage and examples check the [wiki](https://github.com/crypticminds/ColdStorage/wiki)
72+
73+
## @LoadImage Annotation
7174

7275
You can annotate any ImageView present in an Activity , fragement or another view to load images from an URL and cache it for future use.
7376

@@ -81,15 +84,12 @@ You can annotate any ImageView present in an Activity , fragement or another vie
8184
```
8285

8386
Images can be persisted into the internal storage using the **"persistImageToDisk"** parameter.
84-
You can specify how long images should be stored in the disk by passing **"timeToLiveForDiskStorage"** to the **Cache.initialize** method.
85-
By default all data is kept in the disk for upto 2 days.
8687

87-
After the image views have been annotated , bind the class where the image views are present using the method
88-
Cache.bind(objectOfClass).
88+
After the image views have been annotated , bind the class where the image views are present using the method **Cache.bind(object).**
8989

9090
You can pass the activity, fragement or the view to which the annotated ImageViews belong to.
91-
In an activity, the method should be called after setContentView and in a fragemnt it should be called
92-
in onViewCreated method.
91+
92+
In an activity, the method should be called after setContentView and in a fragemnt it should be called in **onViewCreated** method.
9393

9494
```kotlin
9595
override fun onCreate(savedInstanceState: Bundle?) {
@@ -103,7 +103,7 @@ Currently the cache can only be bound to an Activity , fragment or view.
103103

104104
## @Freeze Annotation
105105

106-
Annotate your class using the freeze annotation to apply caching logic on top of all the methods present in the class.
106+
Annotate your class using the freeze annotation to apply caching logic on top of all the public methods present in the class.
107107

108108
```kotlin
109109
@Freeze(generatedClassName = "MyBeautifulCacheLayer")
@@ -132,11 +132,8 @@ class MakeRemoteCallWithFreeze {
132132
}
133133
}
134134
```
135-
136-
This will generate a class called "MyBeautifulCacheLayer" . You can use this class to call the methods.
137-
135+
This will generate a class called "**MyBeautifulCacheLayer**" . You can use this class to call the methods.
138136
```kotlin
139-
140137
//you need to implement the OnOperationSuccessfulCallback interface.
141138
val callback = object : OnOperationSuccessfulCallback<String>{
142139
override fun onSuccess(output: String?, operation: String) {
@@ -154,9 +151,8 @@ cacheLayer.makeRemoteCallToServiceA("someString" , callback)
154151
cacheLayer.makeRemoteCallToServiceB(.... )
155152

156153
```
157-
158154
## @Refrigerate Annotation
159-
Annotate your functions using this to keep the output of the function in the cache for a given set of inputs.
155+
Annotate your functions with refrigerate to cache the output of the function for a given set of inputs.
160156

161157
```kotlin
162158
@Refrigerate(timeToLive : 2000, operation = "cacheImage")
@@ -180,16 +176,10 @@ To invoke the above functions you will call :-
180176
GeneratedCacheLayer.callRemoteService("myurl", "mydata" , "myrandomVariable" , objectOfTheClassWhereTheMethodBelongs , callback)
181177
```
182178
183-
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.
184-
185-
> After applying the annotation you can try running your application on AVD so that the GeneratedCacheLayer file is created. Then use it just like
186-
> a regular class in your project. Your IDE will be able to index it
187-
> after it is generated and you will be able see the parameters the generated functions will accept. The generated file will change when you change your annotated functions.
188-
179+
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.
189180
190181
## Create a custom cache layer
191182
192-
193183
Create your cache layer by extending the **Cache class**. You will have to implement the update method.
194184
The update method should take care of fetching the data when the data is stale or is not present in the cache.
195185
@@ -334,8 +324,24 @@ Optionally you can also pass a time to live value and a converter. They are expl
334324

335325
**The converter object takes care of deserializing the string into the object you need. It is an optional parameter. If the converter is not passed the cache will return the value as string.**
336326

337-
## Other usage
327+
# License
328+
```
329+
Copyright 2020 Anurag Mandal
330+
331+
Licensed under the Apache License, Version 2.0 (the "License");
332+
you may not use this file except in compliance with the License.
333+
You may obtain a copy of the License at
334+
335+
http://www.apache.org/licenses/LICENSE-2.0
336+
337+
Unless required by applicable law or agreed to in writing, software
338+
distributed under the License is distributed on an "AS IS" BASIS,
339+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
340+
See the License for the specific language governing permissions and
341+
limitations under the License.
342+
```
343+
344+
## Author
345+
346+
Anurag Mandal [LinkedIn]( https://www.linkedin.com/in/anurag-mandal-86a65b164/)
338347

339-
* You can update the cache manually using the **addToCache** method. Use this method if you need to update the cache from a sperate async task . You will need to pass the key , and the value (the value needs to be serializable). You can also pass an optional time to live value.
340-
* You can persist your application cache into the shared preferences for future use by calling the method **commitToSharedPref** .
341-
* You can fetch the data from cache without it internally calling the update method if the data is stale or missing by using the method **getWithoutUpdate** . If you are using this method then you do not have to implement the update method of your cache. You will also have to manually fetch the data and update the cache using **addToCache** method when there is a cache miss.

0 commit comments

Comments
 (0)