Fuse is a simple generic LRU cache for Android, backed by both memory cache (LruCache) and disk-based cache (DiskLruCache) by Jake Wharton
Here is how you might wanna use Fuse to cache your network call.
Fuse.init(cacheDir.path)
Fuse.jsonCache.get(URL("http://jsonplaceholder.typicode.com/users/1")) { result ->
result.success { json ->
//do something with json object (result is Result<JsonObject, Exception>)
}
}
//if you wanna know source of cache, can be either MEM(LruCache), DISK(DiskLruCache), NOT_FOUND(newly fetched)
Fuse.stringCache.get(filesDir.resolve("json.txt")) { result, type ->
//do something with string object (result is Result<String, Exception>)
when (type) {
Cache.Type.NOT_FOUND ->
Cache.Type.MEM ->
Cache.Type.DISK ->
}
}
Yeah, that's about it.
Use jitpack.io
repositories {
maven { url "https://jipack.io" }
}
dependencies {
compile 'com.github.kittinunf:fuse:master-SNAPSHOT'
}
- Fuse searches at 1st layer at LruCache (Memory), if found, delivers. If not found go to 2.
- Fuse searches at 2nd layer at DiskLruCache (Disk), if found delivers, If not found go to 3.
- Fuse performs fetch (by conformance with Fetcher interface), then store into LruCache and DiskCache, respectively. Subsequent uses will be much faster by going through 1 & 2.
Fuse itself, is released under MIT of course, but as Fuse depends on LruCache and DiskLruCache. Licenses on dependencies still applies.
Copyright 2011 The Android Open Source Project
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.