Fuse

General

Category
Free
Tag
Caching
License
MIT License
Min SDK
12 (Android 3.1 Honeycomb)
Registered
May 31, 2016
Favorites
1
Link
https://github.com/kittinunf/Fuse
See also
CacheFileProvider
RxCache
QuitNow!'s cache
Reservoir
Storo

Additional

Language
Kotlin
Version
0.2.0-new (Sep 9, 2017)
Created
Apr 25, 2016
Updated
Sep 9, 2017
Owner
Kittinun Vantasin (kittinunf)
Contributors
Kittinun Vantasin (kittinunf)
babedev
2
Activity
Badge
Generate
Download
Source code
APK file

Commercial

Fuse

The simple generic LRU cache for Android, backed by both memory cache ( LruCache) and disk-based cache ( DiskLruCache) by Jake Wharton

TLDR

Here is how you might wanna use Fuse to cache your network call.

Fuse.init(cacheDir.path)

//jsonCache depends on Gson
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.

Installation

Dependency

Gradle

repositories {
    jcenter()
}
dependencies {
    compile 'com.github.kittinunf.fuse:fuse:<latest-version>'
}

Detail Usage

Built-in Cache

By default, Fuse has built-in Byte, String and JSONObject cache by using Fuse.byteCache, Fuse.stringCache and Fuse.jsonCache respectively

Remove

You can remove specific cache by using Key

Fuse.bytesCache.remove("key") //same for stringCache and jsonCache

Advanced Usage

How it works?

  1. Fuse searches at 1st layer at LruCache (Memory), if found, delivers. If not found go to 2.
  2. Fuse searches at 2nd layer at DiskLruCache (Disk), if found delivers, If not found go to 3.
  3. Fuse performs fetch (by conformance with Fetcher interface), then store into LruCache and DiskCache, respectively. Therefore, subsequent uses will be much faster by going through 1 & 2.

License

Fuse is released under MIT, but as Fuse depends on LruCache and DiskLruCache. Licenses agreement on both dependencies 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.