{"id":17968656,"url":"https://github.com/kittinunf/fuse","last_synced_at":"2025-04-07T07:17:57.079Z","repository":{"id":8164174,"uuid":"57063889","full_name":"kittinunf/Fuse","owner":"kittinunf","description":"The simple generic LRU memory/disk cache for Android written in Kotlin","archived":false,"fork":false,"pushed_at":"2022-06-01T07:42:44.000Z","size":5704,"stargazers_count":284,"open_issues_count":3,"forks_count":27,"subscribers_count":10,"default_branch":"master","last_synced_at":"2025-03-31T06:06:56.133Z","etag":null,"topics":["android","cache","disklrucache","kotlin","lru-cache"],"latest_commit_sha":null,"homepage":"https://kittinunf.gitbook.io/fuse/","language":"Kotlin","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/kittinunf.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":".github/FUNDING.yml","license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null},"funding":{"github":["kittinunf"]}},"created_at":"2016-04-25T18:00:04.000Z","updated_at":"2025-02-10T17:36:39.000Z","dependencies_parsed_at":"2022-08-06T20:15:32.032Z","dependency_job_id":null,"html_url":"https://github.com/kittinunf/Fuse","commit_stats":null,"previous_names":[],"tags_count":14,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kittinunf%2FFuse","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kittinunf%2FFuse/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kittinunf%2FFuse/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kittinunf%2FFuse/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/kittinunf","download_url":"https://codeload.github.com/kittinunf/Fuse/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247608160,"owners_count":20965953,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["android","cache","disklrucache","kotlin","lru-cache"],"created_at":"2024-10-29T14:41:09.764Z","updated_at":"2025-04-07T07:17:57.057Z","avatar_url":"https://github.com/kittinunf.png","language":"Kotlin","funding_links":["https://github.com/sponsors/kittinunf"],"categories":[],"sub_categories":[],"readme":"# Fuse\n\n[![MavenCentral](https://maven-badges.herokuapp.com/maven-central/com.github.kittinunf.fuse/fuse/badge.svg)](https://search.maven.org/search?q=g:com.github.kittinunf.fuse)\n[![Build Status](https://travis-ci.org/kittinunf/fuse.svg?branch=master)](https://travis-ci.org/kittinunf/fuse)\n[![Codecov](https://codecov.io/github/kittinunf/Fuse/coverage.svg?branch=master)](https://codecov.io/gh/kittinunf/Fuse)\n\nThe simple generic LRU cache for Android, backed by both memory cache ([LruCache](http://developer.android.com/reference/android/util/LruCache.html)) and disk-based cache ([DiskLruCache](https://github.com/JakeWharton/DiskLruCache)) by Jake Wharton \n\n# Installation\n\nThe core package has following dependencies;\n\n- [![Kotlin](https://img.shields.io/badge/Kotlin-1.6.20-blue.svg)](http://kotlinlang.org)\n- [Result](https://github.com/kittinunf/Result) - 5.2.1\n\n```groovy\n  //core\n  implementation 'com.github.kittinunf.fuse:fuse:\u003clatest-version\u003e'\n  \n  //android\n  implementation 'com.github.kittinunf.fuse:fuse-android:\u003clatest-version\u003e'\n```\n\n# How to use\n\n`Fuse` is designed to be simple and easy to use. All you need is `CacheBuilder` to setup configuration for your cache. \n\n```kotlin\nprivate val tempDir = createTempDir().absolutePath // use any readable/writable directory of your choice\n\nval convertible = // there are couple of built-in Convertibles such as DataConvertible, StringDataConvertible\nval cache = CacheBuilder.config(tempDir, convertible) { \n  // do more configuration here\n}.build()\n```\n\nThen, you can build `Cache` from the `CacheBuilder` and, you can start using your cache like;\n\n```kotlin\ncache = //cache instance that was instantiated earlier\n\n//put value \"world\" for key \"hello\", \"put\" will always add new value into the cache\ncache.put(\"hello\", { \"world\" })\n\n//later\ncache.get(\"hello\") // this returns Result.Success[\"world\"]\nval (result, source) = cache.getWithSource(\"hello\") // this also returns Source which is one of the following, 1. MEM, 2. DISK, 3. ORIGIN\n\n\nval result = cache.get(\"hello\", { \"world\" }) // this return previously cached value otherwise it will save value \"world\" into the cache for later use\nwhen (result) {\n  is Success -\u003e { // value is successfully return/fetch, result.value is data \n  }\n  is Failure -\u003e { // something wrong, check result.error for more details \n  }\n}\n```\n\n### Source\n\n`Source` gives you an information where the data is coming from.\n\n```kotlin\nenum class Source {\n  ORIGIN,\n  DISK,\n  MEM\n}\n```\n\n- ORIGIN - The data is coming from the original source. This means that it is being fetched from the `Fetcher\u003cT\u003e` class.\n- DISK - The data is coming from the Disk cache. In this cache, it is specifically retrieved from DiskLruCache\n- MEM - The data is coming from the memory cache.\n\nAll of the interfaces that provides `Source` have `WithSource` suffix, i.e. `getWithSource()` etc.\n\n### Android Usage\n\nFor Android, it is basically a thin layer on top of the memory cache by using a [LruCache](https://developer.android.com/reference/android/util/LruCache)\n\n```kotlin\n// same configuration as above\nval cache = CacheBuilder.config(tempDir, convertible) {\n  // do more configuration here\n  memCache = defaultAndroidMemoryCache() // this will utilize the LruCache provided by Android SDK\n}.build()\n```\n\nBy default, the Cache is perpetual meaning that it will never expired by itself. Please check [Detail Usage] for more information about expirable cache.\n\n# Detailed usage\n\nThe default Cache that is provided by Fuse is a perpetual cache that will never expire the entry. In some cases, this is not what you want. If you are looking for non-perpetual cache, luckily, Fuse also provides you with a `ExpirableCache` as well. \n\nThe usage of `ExpirableCache` is almost exactly the same as a regular cache, but with a time constraint that is configurable for the entry to be expired.\n\n```kotlin\nprivate val cache = CacheBuilder.config(tempDir, StringDataConvertible()).build().let(::ExpirableCache)\n\n// cache is ExpirableCache type\nval (value, error) = expirableCache.get(\"hello\", { \"world\" }) // this works the same as regular cache\n\nprintln(value) //Result.Success[\"world\"]\n\n// after 5 seconds has passed\nval (value, error) = expirableCache.get(\"hello\", { \"new world\" }, timeLimit = 5.seconds) // if the cached value has a lifetime longer than 5 seconds, entry becomes invalid\n\nprintln(value) //Result.Success[\"new world\"], it got refreshed as the entry is expired\n```\n\n# Sample\n\nPlease see the sample Android app that utilize Fuse in the [Sample](https://github.com/kittinunf/Fuse/tree/master/sample) folder\n\n## License\n\nFuse is released under [MIT](https://opensource.org/licenses/MIT), but as Fuse depends on LruCache and DiskLruCache. Licenses agreement on both dependencies applies.\n\n```\nCopyright 2011 The Android Open Source Project\n\nLicensed under the Apache License, Version 2.0 (the \"License\");\nyou may not use this file except in compliance with the License.\nYou may obtain a copy of the License at\n\n   http://www.apache.org/licenses/LICENSE-2.0\n\nUnless required by applicable law or agreed to in writing, software\ndistributed under the License is distributed on an \"AS IS\" BASIS,\nWITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\nSee the License for the specific language governing permissions and\nlimitations under the License.\n```\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkittinunf%2Ffuse","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fkittinunf%2Ffuse","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkittinunf%2Ffuse/lists"}