{"id":13604169,"url":"https://github.com/VictorAlbertos/RxCache","last_synced_at":"2025-04-11T23:31:50.948Z","repository":{"id":85040017,"uuid":"49391150","full_name":"VictorAlbertos/RxCache","owner":"VictorAlbertos","description":"Reactive caching library for Android and Java","archived":true,"fork":false,"pushed_at":"2020-08-09T13:34:50.000Z","size":6781,"stargazers_count":2372,"open_issues_count":21,"forks_count":192,"subscribers_count":60,"default_branch":"2.x","last_synced_at":"2025-01-18T19:36:43.723Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Java","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/VictorAlbertos.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.txt","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null}},"created_at":"2016-01-10T23:49:22.000Z","updated_at":"2025-01-15T09:16:33.000Z","dependencies_parsed_at":null,"dependency_job_id":"5d605b4a-f9c2-4723-add3-cdff39c7130f","html_url":"https://github.com/VictorAlbertos/RxCache","commit_stats":null,"previous_names":[],"tags_count":64,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/VictorAlbertos%2FRxCache","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/VictorAlbertos%2FRxCache/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/VictorAlbertos%2FRxCache/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/VictorAlbertos%2FRxCache/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/VictorAlbertos","download_url":"https://codeload.github.com/VictorAlbertos/RxCache/tar.gz/refs/heads/2.x","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248495013,"owners_count":21113546,"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":[],"created_at":"2024-08-01T19:00:41.001Z","updated_at":"2025-04-11T23:31:50.286Z","avatar_url":"https://github.com/VictorAlbertos.png","language":"Java","funding_links":[],"categories":["Java","缓存库"],"sub_categories":[],"readme":":warning: This repository is no longer mantained consider using [Room](https://developer.android.com/topic/libraries/architecture/room) as an alternative :warning: \r\n\r\n![Downloads](https://jitpack.io/v/VictorAlbertos/RxCache/month.svg)\r\n\r\n[![Android Arsenal](https://img.shields.io/badge/Android%20Arsenal-RxCache-green.svg?style=true)](https://android-arsenal.com/details/1/3016)\r\n\r\n# RxCache\r\n\r\n\u003e [**中文文档**](http://www.jianshu.com/p/b58ef6b0624b)\r\n\r\n_For a more reactive approach go [here](https://github.com/VictorAlbertos/ReactiveCache/tree/2.x)_.\r\n\r\nThe **goal** of this library is simple: **caching your data models like [Picasso](https://github.com/square/picasso) caches your images, with no effort at all.** \r\n\r\nEvery Android application is a client application, which means it does not make sense to create and maintain a database just for caching data.\r\n\r\nPlus, the fact that you have some sort of legendary database for persisting your data does not solves by itself the real challenge: to be able to configure your caching needs in a flexible and simple way. \r\n\r\nInspired by [Retrofit](http://square.github.io/retrofit/) api, **RxCache is a reactive caching library for Android and Java which turns your caching needs into an interface.** \r\n\r\nWhen supplying an **`observable`, `single`, `maybe` or `flowable` (these are the supported Reactive types)** which contains the data provided by an expensive task -probably an http connection, RxCache determines if it is needed \r\nto subscribe to it or instead fetch the data previously cached. This decision is made based on the providers configuration.\r\n \r\n```java\r\nObservable\u003cList\u003cMock\u003e\u003e getMocks(Observable\u003cList\u003cMock\u003e\u003e oMocks);\r\n```\r\n\r\n## Setup\r\n\r\nAdd the JitPack repository in your build.gradle (top level module):\r\n```gradle\r\nallprojects {\r\n    repositories {\r\n        jcenter()\r\n        maven { url \"https://jitpack.io\" }\r\n    }\r\n}\r\n```\r\n\r\nAnd add next dependencies in the build.gradle of the module:\r\n```gradle\r\ndependencies {\r\n    compile \"com.github.VictorAlbertos.RxCache:runtime:1.8.3-2.x\"\r\n    compile \"io.reactivex.rxjava2:rxjava:2.1.6\"\r\n}\r\n```\r\n\r\nBecause RxCache uses internally [Jolyglot](https://github.com/VictorAlbertos/Jolyglot) to serialize and deserialize objects, you need to add one of the next dependency to gradle.\r\n \r\n```gradle\r\ndependencies {\r\n    // To use Gson \r\n    compile 'com.github.VictorAlbertos.Jolyglot:gson:0.0.4'\r\n    \r\n    // To use Jackson\r\n    compile 'com.github.VictorAlbertos.Jolyglot:jackson:0.0.4'\r\n    \r\n    // To use Moshi\r\n    compile 'com.github.VictorAlbertos.Jolyglot:moshi:0.0.4'\r\n}\r\n```\r\n\r\n## Usage\r\n\r\nDefine an `interface` with as much methods as needed to create the caching providers:\r\n\r\n```java\r\ninterface Providers {\r\n\r\n        @ProviderKey(\"mocks\")\r\n        Observable\u003cList\u003cMock\u003e\u003e getMocks(Observable\u003cList\u003cMock\u003e\u003e oMocks);\r\n    \r\n        @ProviderKey(\"mocks-5-minute-ttl\")\r\n        @LifeCache(duration = 5, timeUnit = TimeUnit.MINUTES)\r\n        Observable\u003cList\u003cMock\u003e\u003e getMocksWith5MinutesLifeTime(Observable\u003cList\u003cMock\u003e\u003e oMocks);\r\n    \r\n        @ProviderKey(\"mocks-evict-provider\")\r\n        Observable\u003cList\u003cMock\u003e\u003e getMocksEvictProvider(Observable\u003cList\u003cMock\u003e\u003e oMocks, EvictProvider evictProvider);\r\n    \r\n        @ProviderKey(\"mocks-paginate\")\r\n        Observable\u003cList\u003cMock\u003e\u003e getMocksPaginate(Observable\u003cList\u003cMock\u003e\u003e oMocks, DynamicKey page);\r\n    \r\n        @ProviderKey(\"mocks-paginate-evict-per-page\")\r\n        Observable\u003cList\u003cMock\u003e\u003e getMocksPaginateEvictingPerPage(Observable\u003cList\u003cMock\u003e\u003e oMocks, DynamicKey page, EvictDynamicKey evictPage);\r\n        \r\n        @ProviderKey(\"mocks-paginate-evict-per-filter\")\r\n        Observable\u003cList\u003cMock\u003e\u003e getMocksPaginateWithFiltersEvictingPerFilter(Observable\u003cList\u003cMock\u003e\u003e oMocks, DynamicKeyGroup filterPage, EvictDynamicKey evictFilter);\r\n}\r\n```\r\n\r\nRxCache exposes `evictAll()` method to evict the entire cache in a row. \r\n\r\nRxCache accepts as argument a set of classes to indicate how the provider needs to handle the cached data:\r\n\r\n* A Reactive type is the only object required to create a provider. This Reactive type must be equal to the one specified by the returning value of the provider.\r\n* [EvictProvider](https://github.com/VictorAlbertos/RxCache/blob/master/core/src/main/java/io/rx_cache/EvictProvider.java) allows to explicitly evict all the data associated with the provider.\r\n* [@ProviderKey](https://github.com/VictorAlbertos/RxCache/blob/master/core/src/main/java/io/rx_cache/ProviderKey.java) is an annotation for provider methods that is highly recommended to use and proguard users MUST use this annotation, if not used the method names will be used as provider keys (cache keys) and proguard users will quickly run into problems, please see [Proguard](proguard) for detailed information. Using the annotaiton is also useful when not using Proguard as it makes sure you can change your method names without having to write a migration for old cache files.\r\n* [EvictDynamicKey](https://github.com/VictorAlbertos/RxCache/blob/master/core/src/main/java/io/rx_cache/EvictDynamicKey.java) allows to explicitly evict the data of an specific [DynamicKey](https://github.com/VictorAlbertos/RxCache/blob/master/runtime/src/main/java/io/rx_cache/DynamicKey.java).\r\n* [EvictDynamicKeyGroup](https://github.com/VictorAlbertos/RxCache/blob/master/core/src/main/java/io/rx_cache/EvictDynamicKeyGroup.java) allows to explicitly evict the data of an specific [DynamicKeyGroup](https://github.com/VictorAlbertos/RxCache/blob/master/runtime/src/main/java/io/rx_cache/DynamicKeyGroup.java).\r\n* [DynamicKey](https://github.com/VictorAlbertos/RxCache/blob/master/runtime/src/main/java/io/rx_cache/DynamicKey.java) is a wrapper around the key object for those providers which need to handle multiple records, so they need to provide multiple keys, such us endpoints with pagination, ordering or filtering requirements. To evict the data associated with one particular key use `EvictDynamicKey`.\r\n* [DynamicKeyGroup](https://github.com/VictorAlbertos/RxCache/blob/master/runtime/src/main/java/io/rx_cache/DynamicKeyGroup.java) is a wrapper around the key and the group for those providers which need to handle multiple records grouped, so they need to provide multiple keys organized in groups, such us endpoints with filtering AND pagination requirements. To evict the data associated with the key of one particular group, use `EvictDynamicKeyGroup`.\r\n\r\nSupported annotations:\r\n\r\n* [@LifeCache](https://github.com/VictorAlbertos/RxCache/blob/master/runtime/src/main/java/io/rx_cache/LifeCache.java) sets the amount of time before the data would be evicted. If `@LifeCache` is not supplied, the data will be never evicted unless it is required explicitly using [EvictProvider](https://github.com/VictorAlbertos/RxCache/blob/master/core/src/main/java/io/rx_cache/EvictProvider.java), [EvictDynamicKey](https://github.com/VictorAlbertos/RxCache/blob/master/core/src/main/java/io/rx_cache/EvictDynamicKey.java) or [EvictDynamicKeyGroup](https://github.com/VictorAlbertos/RxCache/blob/master/core/src/main/java/io/rx_cache/EvictDynamicKeyGroup.java) .\r\n* [@Actionable](https://github.com/VictorAlbertos/RxCache/blob/master/runtime/src/main/java/io/rx_cache/Actionable.java) offers an easy way to perform write operations using providers. More details [here](#actionable_section)\r\n* [@SchemeMigration](https://github.com/VictorAlbertos/RxCache/blob/master/runtime/src/main/java/io/rx_cache/SchemeMigration.java) and [@Migration](https://github.com/VictorAlbertos/RxCache/blob/master/runtime/src/main/java/io/rx_cache/Migration.java) provides a simple mechanism for handling migrations between releases. More details [here](#migrations_section)\r\n* [@Expirable](https://github.com/VictorAlbertos/RxCache/blob/master/runtime/src/main/java/io/rx_cache/Expirable.java) determines if that provider will be excluded from the evicting process or not. More details [here](#expirable_section)\r\n* [@EncryptKey](https://github.com/VictorAlbertos/RxCache/blob/master/runtime/src/main/java/io/rx_cache/EncryptKey.java) and [@Encrypt](https://github.com/VictorAlbertos/RxCache/blob/master/runtime/src/main/java/io/rx_cache/Encrypt.java) provides a simple way to encrypt/decrypt the data on persistence layer. More details [here](#encryption_section)\r\n\r\n### Build an instance of Providers and use it\r\n\r\nFinally, instantiate the Providers `interface` using `RxCache.Builder` and supplying a valid file system path which would allow RxCache to write on disk.\r\n\r\n```java\r\nFile cacheDir = getFilesDir();\r\nProviders providers = new RxCache.Builder()\r\n                            .persistence(cacheDir, new GsonSpeaker())\r\n                            .using(Providers.class);\r\n```\r\n\r\n### Putting It All Together\r\n\r\n```java\r\ninterface Providers {\r\n\r\n    @ProviderKey(\"mocks-evict-provider\")\r\n    Observable\u003cList\u003cMock\u003e\u003e getMocksEvictProvider(Observable\u003cList\u003cMock\u003e\u003e oMocks, EvictProvider evictProvider);\r\n\r\n    @ProviderKey(\"mocks-paginate-evict-per-page\")\r\n    Observable\u003cList\u003cMock\u003e\u003e getMocksPaginateEvictingPerPage(Observable\u003cList\u003cMock\u003e\u003e oMocks, DynamicKey page, EvictDynamicKey evictPage);\r\n\r\n    @ProviderKey(\"mocks-paginate-evict-per-filter\")\r\n    Observable\u003cList\u003cMock\u003e\u003e getMocksPaginateWithFiltersEvictingPerFilter(Observable\u003cList\u003cMock\u003e\u003e oMocks, DynamicKeyGroup filterPage, EvictDynamicKey evictFilter);\r\n}\r\n```\r\n\r\n```java\r\npublic class Repository {\r\n    private final Providers providers;\r\n\r\n    public Repository(File cacheDir) {\r\n        providers = new RxCache.Builder()\r\n                .persistence(cacheDir, new GsonSpeaker())\r\n                .using(Providers.class);\r\n    }\r\n\r\n    public Observable\u003cList\u003cMock\u003e\u003e getMocks(final boolean update) {\r\n        return providers.getMocksEvictProvider(getExpensiveMocks(), new EvictProvider(update));\r\n    }\r\n\r\n    public Observable\u003cList\u003cMock\u003e\u003e getMocksPaginate(final int page, final boolean update) {\r\n        return providers.getMocksPaginateEvictingPerPage(getExpensiveMocks(), new DynamicKey(page), new EvictDynamicKey(update));\r\n    }\r\n\r\n    public Observable\u003cList\u003cMock\u003e\u003e getMocksWithFiltersPaginate(final String filter, final int page, final boolean updateFilter) {\r\n        return providers.getMocksPaginateWithFiltersEvictingPerFilter(getExpensiveMocks(), new DynamicKeyGroup(filter, page), new EvictDynamicKey(updateFilter));\r\n    }\r\n\r\n    //In a real use case, here is when you build your observable with the expensive operation.\r\n    //Or if you are making http calls you can use Retrofit to get it out of the box.\r\n    private Observable\u003cList\u003cMock\u003e\u003e getExpensiveMocks() {\r\n        return Observable.just(Arrays.asList(new Mock(\"\")));\r\n    }\r\n}\r\n```\r\n\r\n## Use cases\r\n* Using classic API RxCache for read actions with little write needs.\r\n* Using actionable API RxCache, exclusive for write actions.\r\n\r\n## Classic API RxCache:\r\n\r\nFollowing use cases illustrate some common scenarios which will help to understand the usage of `DynamicKey` and `DynamicKeyGroup` classes along with evicting scopes.\r\n\r\n### List\r\n\r\nList without evicting:\r\n```java\r\nObservable\u003cList\u003cMock\u003e\u003e getMocks(Observable\u003cList\u003cMock\u003e\u003e oMocks);\r\n```\r\n\r\nList evicting:\r\n```java\r\nObservable\u003cList\u003cMock\u003e\u003e getMocksEvictProvider(Observable\u003cList\u003cMock\u003e\u003e oMocks, EvictProvider evictProvider);\r\n```\r\n\r\n\u003e Runtime usage:\r\n\r\n```java\r\n//Hit observable evicting all mocks\r\ngetMocksEvictProvider(oMocks, new EvictProvider(true))\r\n\r\n//This line throws an IllegalArgumentException: \"EvictDynamicKey was provided but not was provided any DynamicKey\"\r\ngetMocksEvictProvider(oMocks, new EvictDynamicKey(true))\r\n```\r\n\r\n### List Filtering\r\n\r\nList filtering without evicting:\r\n```java\r\nObservable\u003cList\u003cMock\u003e\u003e getMocksFiltered(Observable\u003cList\u003cMock\u003e\u003e oMocks, DynamicKey filter);\r\n```\r\n\r\n\r\nList filtering evicting:\r\n```java\r\nObservable\u003cList\u003cMock\u003e\u003e getMocksFilteredEvict(Observable\u003cList\u003cMock\u003e\u003e oMocks, DynamicKey filter, EvictProvider evictDynamicKey);\r\n```\r\n\r\n\u003e Runtime usage:\r\n\r\n```java\r\n//Hit observable evicting all mocks using EvictProvider\r\ngetMocksFilteredEvict(oMocks, new DynamicKey(\"actives\"), new EvictProvider(true))\r\n\r\n//Hit observable evicting mocks of one filter using EvictDynamicKey\r\ngetMocksFilteredEvict(oMocks, new DynamicKey(\"actives\"), new EvictDynamicKey(true))\r\n\r\n//This line throws an IllegalArgumentException: \"EvictDynamicKeyGroup was provided but not was provided any Group\"\r\ngetMocksFilteredEvict(oMocks, new DynamicKey(\"actives\"), new EvictDynamicKeyGroup(true))\r\n```\r\n\r\n### List Paginated with filters\r\n\r\nList paginated with filters without evicting:\r\n```java\r\nObservable\u003cList\u003cMock\u003e\u003e getMocksFilteredPaginate(Observable\u003cList\u003cMock\u003e\u003e oMocks, DynamicKey filterAndPage);\r\n```\r\n\r\n\r\nList paginated with filters evicting:\r\n```java\r\nObservable\u003cList\u003cMock\u003e\u003e getMocksFilteredPaginateEvict(Observable\u003cList\u003cMock\u003e\u003e oMocks, DynamicKeyGroup filterAndPage, EvictProvider evictProvider);\r\n```\r\n\r\n\u003e Runtime usage:\r\n\r\n```java\r\n//Hit observable evicting all mocks using EvictProvider\r\ngetMocksFilteredPaginateEvict(oMocks, new DynamicKeyGroup(\"actives\", \"page1\"), new EvictProvider(true))\r\n\r\n//Hit observable evicting all mocks pages of one filter using EvictDynamicKey\r\ngetMocksFilteredPaginateEvict(oMocks, new DynamicKeyGroup(\"actives\", \"page1\"), new EvictDynamicKey(true))\r\n\r\n//Hit observable evicting one page mocks of one filter using EvictDynamicKeyGroup\r\ngetMocksFilteredPaginateInvalidate(oMocks, new DynamicKeyGroup(\"actives\", \"page1\"), new EvictDynamicKeyGroup(true))\r\n```\r\n\r\nAs you may already notice, the whole point of using `DynamicKey` or `DynamicKeyGroup` along with `Evict` classes is to play with several scopes when evicting objects.\r\n\r\nThe above examples declare providers which their method signature accepts `EvictProvider` in order to be able to concrete more specifics types of `EvictProvider` at runtime.\r\n\r\nBut I have done that for demonstration purposes, you always should narrow the evicting classes in your method signature to the type which you really need. For the last example, I would use `EvictDynamicKey` in production code, because this way I would be able to paginate the filtered items and evict them per its filter, triggered by a pull to refresh for instance.\r\n\r\nNevertheless, there are complete examples for [Android and Java projects](https://github.com/VictorAlbertos/RxCacheSamples).\r\n\r\n## \u003ca name=\"actionable_section\"\u003e\u003c/a\u003eActionable API RxCache:\r\n\r\n**Limitation: This actionable API only support `Observable` as Reactive type.**\r\n\r\nThis actionable api offers an easy way to perform write operations using providers. Although write operations could be achieved using the classic api too, it's much complex and error-prone. Indeed, the [Actions](https://github.com/VictorAlbertos/RxCache/blob/master/runtime/src/main/java/io/rx_cache/ActionsList.java) class it's a wrapper around the classic api which play with evicting scopes and lists.\r\n\r\nIn order to use this actionable api, first you need to add the [repository compiler](https://github.com/VictorAlbertos/RxCache/tree/master/compiler) as a dependency to your project using an annotation processor. For Android, it would be as follows:\r\n\r\nAdd this line to your root build.gradle:\r\n\r\n```gradle\r\ndependencies {\r\n     // other classpath definitions here\r\n     classpath 'com.neenbedankt.gradle.plugins:android-apt:1.8'\r\n }\r\n```\r\n\r\n\r\nThen make sure to apply the plugin in your app/build.gradle and add the compiler dependency:\r\n\r\n```gradle\r\napply plugin: 'com.neenbedankt.android-apt'\r\n\r\ndependencies {\r\n    // apt command comes from the android-apt plugin\r\n    apt \"com.github.VictorAlbertos.RxCache:compiler:1.8.3-2.x\"\r\n}\r\n```\r\n\r\nAfter this configuration, every provider annotated with [@Actionable](https://github.com/VictorAlbertos/RxCache/blob/master/runtime/src/main/java/io/rx_cache/Actionable.java) `annotation` \r\nwill expose an accessor method in a new generated class called with the same name as the interface, but appending an 'Actionable' suffix.\r\n\r\nThe order in the params supplies must be as in the following example:\r\n\r\n```java\r\npublic interface RxProviders {\r\n    @Actionable\r\n    Observable\u003cList\u003cMock.InnerMock\u003e\u003e mocks(Observable\u003cList\u003cMock.InnerMock\u003e\u003e message, EvictProvider evictProvider);\r\n\r\n    @Actionable\r\n    Observable\u003cList\u003cMock\u003e\u003e mocksDynamicKey(Observable\u003cList\u003cMock\u003e\u003e message, DynamicKey dynamicKey, EvictDynamicKey evictDynamicKey);\r\n\r\n    @Actionable\r\n    Observable\u003cList\u003cMock\u003e\u003e mocksDynamicKeyGroup(Observable\u003cList\u003cMock\u003e\u003e message, DynamicKeyGroup dynamicKeyGroup, EvictDynamicKeyGroup evictDynamicKey);\r\n}\r\n```\r\n\r\nThe observable value must be a `List`, otherwise an error will be thrown.\r\n\r\nThe previous RxProviders `interface` will expose the next accessors methods in the generated `RxProvidersActionable` class.\r\n```java\r\nRxProvidersActionable.mocks(RxProviders proxy);\r\nRxProvidersActionable.mocksDynamicKey(RxProviders proxy, DynamicKey dynamicKey);\r\nRxProvidersActionable.mocksDynamicKeyGroup(RxProviders proxy, DynamicKeyGroup dynamicKeyGroup);\r\n```\r\n\r\nThese methods return an instance of the `Actions` class, so now you are ready to use every write operation available in the [Actions](https://github.com/VictorAlbertos/RxCache/blob/master/runtime/src/main/java/io/rx_cache/ActionsList.java) class. It is advisable to explore the [ActionsTest](https://github.com/VictorAlbertos/RxCache/blob/master/runtime/src/test/java/io/rx_cache/internal/ActionsListTest.java) class to see what action fits better for your case. If you feel that some action has been missed please don't hesitate to open an issue to request it.\r\n\r\nSome actions examples:\r\n\r\n```java\r\nActionsProviders.mocks(rxProviders)\r\n    .addFirst(new Mock())\r\n    .addLast(new Mock())\r\n    //Add a new mock at 5 position\r\n    .add((position, count) -\u003e position == 5, new Mock())\r\n\r\n    .evictFirst()\r\n    //Evict first element if the cache has already 300 records\r\n    .evictFirst(count -\u003e count \u003e 300)\r\n    .evictLast()\r\n    //Evict last element if the cache has already 300 records\r\n    .evictLast(count -\u003e count \u003e 300)\r\n    //Evict all inactive elements\r\n    .evictIterable((position, count, mock) -\u003e mock.isInactive())\r\n    .evictAll()\r\n\r\n    //Update the mock with id 5\r\n    .update(mock -\u003e mock.getId() == 5, mock -\u003e {\r\n        mock.setActive();\r\n        return mock;\r\n    })\r\n    //Update all inactive mocks\r\n    .updateIterable(mock -\u003e mock.isInactive(), mock -\u003e {\r\n        mock.setActive();\r\n        return mock;\r\n    })\r\n    .toObservable()\r\n    .subscribe(processedMocks -\u003e {})\r\n```\r\n\r\nEvery one of the previous actions will be execute only after the composed observable receives a subscription. This way, the underliyng provider cache will be modified its elements without effort at all.\r\n\r\n## \u003ca name=\"migrations_section\"\u003e\u003c/a\u003eMigrations\r\n\r\nRxCache provides a simple mechanism for handling migrations between releases.\r\n\r\nYou need to annotate your providers `interface` with [@SchemeMigration](https://github.com/VictorAlbertos/RxCache/blob/master/runtime/src/main/java/io/rx_cache/SchemeMigration.java). This `annotation` accepts an array of [@Migration](https://github.com/VictorAlbertos/RxCache/blob/master/runtime/src/main/java/io/rx_cache/Migration.java) annotations, and, in turn, `@Migration` annotation accepts both, a version number and an array of `Class`es which will be deleted from persistence layer.\r\n\r\n```java\r\n@SchemeMigration({\r\n            @Migration(version = 1, evictClasses = {Mock.class}),\r\n            @Migration(version = 2, evictClasses = {Mock2.class}),\r\n            @Migration(version = 3, evictClasses = {Mock3.class})\r\n    })\r\ninterface Providers {}\r\n```\r\n\r\nYou want to annotate a new migration only when a new field has been added in a class model used by RxCache.\r\n\r\nDeleting classes or deleting fields of classes would be handle automatically by RxCache, so you don't need to annotate a new migration when a field or an entire class has been deleted.\r\n\r\nFor instance:\r\n\r\nA migration was added at some point. After that, a second one was added eventually.\r\n\r\n```java\r\n@SchemeMigration({\r\n            @Migration(version = 1, evictClasses = {Mock.class}),\r\n            @Migration(version = 2, evictClasses = {Mock2.class})\r\n    })\r\ninterface Providers {}\r\n```\r\n\r\nBut now `Mock` class has been deleted from the project, so it is impossible to reference its class anymore. To fix this, just delete the migration `annotation`.\r\n\r\n```java\r\n@SchemeMigration({\r\n            @Migration(version = 2, evictClasses = {Mock2.class})\r\n    })\r\ninterface Providers {}\r\n```\r\n\r\nBecause RxCache has an internal process to clean memory when it is required, the data will be evicted eventually.\r\n\r\n## \u003ca name=\"encryption_section\"\u003e\u003c/a\u003eEncryption\r\n\r\nRxCache provides a simple mechanism to encrypt the data.\r\n\r\nYou need to annotate your providers `interface` with [@EncryptKey](https://github.com/VictorAlbertos/RxCache/blob/master/runtime/src/main/java/io/rx_cache/EncryptKey.java). This `annotation` accepts a string as the `key` necessary to encrypt/decrypt the data. But you will need to annotate your provider's records with [@Encrypt](https://github.com/VictorAlbertos/RxCache/blob/master/runtime/src/main/java/io/rx_cache/Encrypt.java) in order to saved the data encrypted. If no [@Encrypt](https://github.com/VictorAlbertos/RxCache/blob/master/runtime/src/main/java/io/rx_cache/Encrypt.java) is set, then no encryption will be held. \r\n\r\n**Important:** If the value of the `key` supplied on [@EncryptKey](https://github.com/VictorAlbertos/RxCache/blob/master/runtime/src/main/java/io/rx_cache/EncryptKey.java) is modified between compilations, then the previous persisted data will not be able to be evicted/retrieved by RxCache. \r\n\r\n```java\r\n@EncryptKey(\"myStrongKey-1234\")\r\ninterface Providers {\r\n        @Encrypt\r\n        Observable\u003cList\u003cMock\u003e\u003e getMocksEncrypted(Observable\u003cList\u003cMock\u003e\u003e oMocks);\r\n\r\n        Observable\u003cList\u003cMock\u003e\u003e getMocksNotEncrypted(Observable\u003cList\u003cMock\u003e\u003e oMocks);\r\n}\r\n```\r\n\r\n## Configure general behaviour\r\n\r\nRxCache allows to set certain parameters when building the providers instance:\r\n\r\n### \u003ca name=\"expirable_section\"\u003e\u003c/a\u003eConfigure the limit in megabytes for the data to be persisted\r\n\r\nBy default, RxCache sets the limit in 100 megabytes, but you can change this value by calling setMaxMBPersistenceCache method when building the provider instance.\r\n\r\n```java\r\nnew RxCache.Builder()\r\n            .setMaxMBPersistenceCache(maxMgPersistenceCache)\r\n            .persistence(cacheDir)\r\n            .using(Providers.class);\r\n```\r\n\r\nThis limit ensure that the disk will no grow up limitless in case you have providers with dynamic keys which values changes dynamically, like filters based on gps location or dynamic filters supplied by your back-end solution.\r\n\r\nWhen this limit is reached, RxCache will not be able to persist in disk new data. That's why RxCache has an automated process to evict any record when the threshold memory assigned to the persistence layer is close to be reached, even if the record life time has not been fulfilled.\r\n\r\nBut provider's record annotated with [@Expirable](https://github.com/VictorAlbertos/RxCache/blob/master/runtime/src/main/java/io/rx_cache/Expirable.java) annotation and set its value to false will be excluded from the process.\r\n\r\n```java\r\ninterface Providers {\r\n    @Expirable(false)\r\n    Observable\u003cList\u003cMock\u003e\u003e getMocksNotExpirable(Observable\u003cList\u003cMock\u003e\u003e oMocks);\r\n}\r\n```\r\n\r\n### Use expired data if loader not available\r\n\r\nBy default, RxCache will throw a RuntimeException if the cached data has expired and the data returned by the observable loader is null, \r\npreventing this way serving data which has been marked as evicted.\r\n\r\nYou can modify this behaviour, allowing RxCache serving evicted data when the loader has returned null values, by setting as true the value of useExpiredDataIfLoaderNotAvailable\r\n\r\n```java\r\nnew RxCache.Builder()\r\n            .useExpiredDataIfLoaderNotAvailable(true)\r\n            .persistence(cacheDir)\r\n            .using(Providers.class);\r\n```\r\n\r\n## Android considerations\r\n\r\nTo build an instance of the interface used as provides by RxCache, you need to supply a reference to a file system. On Android, you can get the File reference calling getFilesDir() from the [Android Application](http://developer.android.com/intl/es/reference/android/app/Application.html) class.\r\n\r\nAlso, it is recommended to use this Android Application class to provide a unique instance of RxCache for the entire life cycle of your application.\r\n\r\nIn order execute the Observable on a new thread, and emit results through onNext on the main UI thread, you should use the built in methods provided by [RxAndroid](https://github.com/ReactiveX/RxAndroid).\r\n\r\nCheck the [Android example](https://github.com/VictorAlbertos/RxCacheSamples/tree/master/sample_android)\r\n\r\n## Retrofit\r\n\r\nRxCache is the perfect match for Retrofit to create a repository of auto-managed-caching data pointing to endpoints. \r\nYou can check an [example](https://github.com/VictorAlbertos/RxCacheSamples/blob/master/sample_data/src/main/java/sample_data/Repository.java) of RxCache and Retrofit working together.\r\n\r\n## Internals\r\n\r\nRxCache serves the data from one of its three layers:\r\n\r\n* A memory layer -\u003e Powered by [Apache ReferenceMap](https://commons.apache.org/proper/commons-collections/apidocs/org/apache/commons/collections4/map/ReferenceMap.html).\r\n* A persisting layer -\u003e RxCache uses internally [Jolyglot](https://github.com/VictorAlbertos/Jolyglot) for serialize and deserialize objects.\r\n* A loader layer (the observable supplied by the client library)\r\n\r\nThe policy is very simple: \r\n\r\n* If the data requested is in memory, and It has not been expired, get it from memory.\r\n* Else if the data requested is in persistence layer, and It has not been expired, get it from persistence.\r\n* Else get it from the loader layer. \r\n\r\n## Proguard\r\nProguard users MUST add the two given lines to their proguard configuration file and MUST use the `@ProviderKey` annotation method for every method that is being used as provider. Without the `@ProviderKey` annotation the method name will be used instead which can lead to providers that use the same name, see issue [#96](https://github.com/VictorAlbertos/RxCache/issues/96) for detailed information.\r\n\r\n```\r\n-dontwarn io.rx_cache2.internal.**\r\n-keepclassmembers enum io.rx_cache2.Source { *; }\r\n-keepclassmembernames class * { @io.rx_cache2.* \u003cmethods\u003e; }\r\n```\r\n\r\n\r\n## Author\r\n\r\n**Víctor Albertos**\r\n\r\n* \u003chttps://twitter.com/_victorAlbertos\u003e\r\n* \u003chttps://www.linkedin.com/in/victoralbertos\u003e\r\n* \u003chttps://github.com/VictorAlbertos\u003e\r\n\r\n## RxCache Swift version:\r\n[RxCache](https://github.com/VictorAlbertos/RxSCache): Reactive caching library for Swift.\r\n\r\n## Another author's libraries using RxJava:\r\n* [Mockery](https://github.com/VictorAlbertos/Mockery): Android and Java library for mocking and testing networking layers with built-in support for Retrofit.\r\n* [RxActivityResult](https://github.com/VictorAlbertos/RxActivityResult): A reactive-tiny-badass-vindictive library to break with the OnActivityResult implementation as it breaks the observables chain. \r\n* [RxFcm](https://github.com/VictorAlbertos/RxFcm): RxJava extension for Android Firebase Cloud Messaging (aka fcm).\r\n* [RxSocialConnect](https://github.com/VictorAlbertos/RxSocialConnect-Android): OAuth RxJava extension for Android.\r\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FVictorAlbertos%2FRxCache","html_url":"https://awesome.ecosyste.ms/projects/github.com%2FVictorAlbertos%2FRxCache","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FVictorAlbertos%2FRxCache/lists"}