You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
### 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.
24
19
25
-
## Setup
20
+
# Articles
21
+
*[Caching in general](https://medium.com/@crypticmindscom_5258/caching-made-easy-with-kotlin-part-1-53433c756978)
* Add kotlin-kapt gradle plugin to **app build.gradle** file
28
28
@@ -36,7 +36,7 @@
36
36
37
37
***Check the latest release to get the newest features.***
38
38
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 .**
40
40
41
41
* Create an application class and initialize the cache in the onCreate() method.
42
42
@@ -50,9 +50,9 @@
50
50
super.onCreate()
51
51
Cache.initialize(context = applicationContext)
52
52
}
53
-
54
53
}
55
54
```
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.
56
56
57
57
*Register your application in the android manifest file by providing the **android:name** attribute
58
58
@@ -66,8 +66,11 @@
66
66
android:theme="@style/AppTheme"
67
67
android:name=".application.Application">
68
68
</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
71
74
72
75
You can annotate any ImageView present in an Activity , fragement or another view to load images from an URLand cache it for future use.
73
76
@@ -81,15 +84,12 @@ You can annotate any ImageView present in an Activity , fragement or another vie
81
84
```
82
85
83
86
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.
86
87
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 classwhere the image views are present using the method **Cache.bind(object).**
89
89
90
90
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 andina fragemnt it should be called in**onViewCreated** method.
93
93
94
94
```kotlin
95
95
overridefunonCreate(savedInstanceState:Bundle?) {
@@ -103,7 +103,7 @@ Currently the cache can only be bound to an Activity , fragment or view.
103
103
104
104
## @Freeze Annotation
105
105
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 classusing the freeze annotation to apply caching logic on top of all the public methods present in the class.
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.
189
180
190
181
## Create a custom cache layer
191
182
192
-
193
183
Create your cache layer by extending the **Cache class**. You will have to implement the update method.
194
184
The update method should take care of fetching the data when the data is stale or is not present in the cache.
195
185
@@ -334,8 +324,24 @@ Optionally you can also pass a time to live value and a converter. They are expl
334
324
335
325
**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.**
336
326
337
-
## Other usage
327
+
# License
328
+
```
329
+
Copyright2020AnuragMandal
330
+
331
+
Licensed under the ApacheLicense, Version2.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 Licenseis distributed on an "AS IS"BASIS,
339
+
WITHOUTWARRANTIESORCONDITIONSOFANYKIND, either express or implied.
340
+
See the Licensefor the specific language governing permissions and
* 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