CacheDiskUtils
Earlier, I wrote about CacheUtils as a perfect replacement for ASimpleCache, with a few BUG fixes and optimizations. The API looks like this:
Cache related ->CacheUtils.java
Put: writes data to the cache instance. getBytes: reads bytes from the cache instance. getString: writes data to the cache. Cache read String Instance. GetJSONObject: JSONObject read from the cache Instance. GetJSONArray: cache read JSONArray Instance. The getBitmap: Cache read Bitmap Instance. GetDrawable: cache read Drawable Instance. GetParcelable: cache read Parcelable Instance. GetSerializable: Instance.getCacheSize: Obtain the cache size instance. getCacheCount: Obtain the cache number instance. remove: Remove cache by key instance. clear: Clears all cacheCopy the code
In AndroidUtilCode 1.17.0, CacheUtils has been deprecated by me and can be replaced with CacheDiskUtils, which may be removed in the next major release 1.18.x.
CacheMemoryUtils
The cache tool class CacheMemoryUtils uses LruCache (LRU is Least Recently Used) to implement memory caching. Its API is as follows:
Memory cache related ->CacheMemoryUtils.java -> Test
Get: reads bytes from the cache instance. getCacheCount: obtains the number of caches instance. remove: obtains the number of caches. Remove cache by key instance. clear: Clears all cacheCopy the code
CacheDoubleUtils
Combining CacheDiskUtils for hard disk caching with CacheMemoryUtils for memory caching, we have our CacheDoubleUtils for secondary caching, which has the following API:
Level 2 cache correlation ->CacheDoubleUtils.java -> Test
Put: writes data to the cache instance. getBytes: reads bytes from the cache instance. getString: writes data to the cache. Cache read String Instance. GetJSONObject: JSONObject read from the cache Instance. GetJSONArray: cache read JSONArray Instance. The getBitmap: Drawable: Drawable instance. getParcelable: Drawable instance. getSerializable: Bitmap instance. getSerializable: Drawable instance. getParcelable: Parcelable instance. getSerializable: Read from the cache Serializable Instance. GetCacheDiskSize: access to the Instance. The disk cache size getCacheDiskCount: Get number of disk cache Instance. GetCacheMemoryCount: number of access memory cache Instance. Remove: according to the key value to remove the cache Instance. The clear: clear all cacheCopy the code
For example, if you want to implement RxCache, for example, the compose operator for RxJava and my tool class will make it easy to put data into the cache.
The article is short and detailed, but the implementation of the code is relatively long and thick, to read the source code and test can fork my AndroidUtilCode to see, I believe you will understand my contribution to this tool class.