All Projects → iagocanalejas → retrocache

iagocanalejas / retrocache

Licence: Apache-2.0 license
This library provides an easy way for configure retrofit for use a 2 layer cache (RAM and Disk)

Programming Languages

java
68154 projects - #9 most used programming language

Projects that are alternatives of or similar to retrocache

webpack-plugin-ramdisk
🐏 A webpack plugin for blazing fast builds on a RAM disk / drive
Stars: ✭ 118 (+237.14%)
Mutual labels:  ram, disk
Eram
Open Source RAM Disk
Stars: ✭ 227 (+548.57%)
Mutual labels:  caching, disk
go-disk-buffer
This package helps to work with huge amount of data, which cannot be stored in RAM
Stars: ✭ 39 (+11.43%)
Mutual labels:  ram, disk
cloud disk
本云网盘为您提供优质的文件网络存储和分享服务。具有空间大、速度快、安全稳固,同时永不限速等优点。🎉 🎉 🎉 Please star ^_^(前端请提issues)
Stars: ✭ 56 (+60%)
Mutual labels:  disk
EFCache
Second Level Cache for Entity Framework 6.1
Stars: ✭ 97 (+177.14%)
Mutual labels:  caching
stress
Single-purpose tools to stress resources
Stars: ✭ 24 (-31.43%)
Mutual labels:  disk
express-expeditious
flexible caching middleware for express endpoints
Stars: ✭ 42 (+20%)
Mutual labels:  caching
PSDiskPart
DiskPart PowerShell Module
Stars: ✭ 30 (-14.29%)
Mutual labels:  disk
BaiduDiskSearcher
百度网盘搜索工具(.NET4.0 & Visual Studio 2017)
Stars: ✭ 43 (+22.86%)
Mutual labels:  disk
koa-cache-lite
Zero-dependency koa router cache
Stars: ✭ 27 (-22.86%)
Mutual labels:  caching
django-cached-modelforms
🌟 ModelChoiceField implementation that can accept lists of objects, not just querysets
Stars: ✭ 14 (-60%)
Mutual labels:  caching
stash
Key-value store abstraction with plain and cache driven semantics and a pluggable backend architecture.
Stars: ✭ 71 (+102.86%)
Mutual labels:  caching
fastapi-etag
Convenience library for working with etags in fastapi
Stars: ✭ 19 (-45.71%)
Mutual labels:  caching
DailyBugle
📰Modern MVVM Android application following single activity architecture which fetches news from 🕷️ news API. this repository contains some best practices ⚡ of android development
Stars: ✭ 17 (-51.43%)
Mutual labels:  caching
adonis-cache
Cache provider for AdonisJS framework
Stars: ✭ 66 (+88.57%)
Mutual labels:  caching
trickster
Open Source HTTP Reverse Proxy Cache and Time Series Dashboard Accelerator
Stars: ✭ 1,753 (+4908.57%)
Mutual labels:  caching
Johnny
Melodic Caching for Swift
Stars: ✭ 36 (+2.86%)
Mutual labels:  caching
java-core
Collections of solutions for micro-tasks created while building modules as part of project. Also has very fun stuffs :)
Stars: ✭ 35 (+0%)
Mutual labels:  caching
endorphin
Key-Value based in-memory cache library which supports Custom Expiration Policies
Stars: ✭ 14 (-60%)
Mutual labels:  caching
laravel-localization-route-cache
Translated Route Caching Solution for Laravel Localization
Stars: ✭ 49 (+40%)
Mutual labels:  caching

Android RetroCache

API Build Status Android Arsenal

paypal

Description

This library provide an easy way for configure retrofit with a 2 layer cache (RAM and Disk). To see more details about the cache used visit DualCache

This allow you to improve the data usage of your apps.

Setup

  • Ensure you can pull artifacts from JitPack :
repositories {
    maven { url 'https://jitpack.io' }
}
  • And add to your module gradle file :
android {
    packagingOptions {
        exclude 'META-INF/LICENSE'
        exclude 'META-INF/NOTICE'
    }
}

dependencies {
    compile 'com.github.iagocanalejas:retrocache:<VERSION>'
}

Usage

  1. In your Service Api Interface change all Call<T> return types for CachedCall<T>

    public interface ApiService {
    
        @GET("/")
        Cached<MyObject> getResource();
    
    }
  2. Build your cache. Library include some shortcuts for this tasks but you can always build a full configured cache using DualCache. Just remember cache key type must be String and entry type must be byte[]

    • Basic cache using only RAM.
       DualCache<String, byte[]> mCache = RetroCache.getRamCache(APP_VERSION);
    • Basic cache using both, Disk and Ram, layers.
       DualCache<String, byte[]> mCache = RetroCache.getDualCache(context, APP_VERSION);
    • Basic cache using both, Disk and Ram, layers and setting a life time for entries.
       DualCache<String, byte[]> mCache = RetroCache.getVolatileCache(context, APP_VERSION);
    • You can also get a non configured Builder.
       Builder<String, byte[]> builder = RetroCache.getBuilder(APP_VERSION);

    For see default values in this caches take a look at RetroCache

    Important

    • APP_VERSION is a static integer. When APP_VERSION changes the cache is automatically cleared. It's recommended to use BuildConfig.VERSION_CODE as APP_VERSION
  3. Add the cache to your Retrofit service with one of the following methods.

    retrofitBuilder.addCallAdapterFactory(CachedCallAdapterFactory.create(cache));
    retrofitBuilder.addCallAdapterFactory(CachedCallAdapterFactory.create(context, APP_VERSION));
    retrofitBuilder.addCallAdapterFactory(CachedCallAdapterFactory.createWithExecutor(cache, executor));
  4. Use it as normal retrofit. Just remember to use Cached. All retrofit methods are included, and you can also use methods explained in Included section.

Included

In addition to normal retrofit usage you can also call refresh(callback) to avoid looking in the cache or remove() to invalidate a cached call.

```java
Cached<MyObject> call = ...
call.refresh(new Callback<MyObject>() {
   ...
});
call.remove();
```

RX-Java2

RxJava2 adapter is still in beta. You can use it as normal retrofit rxjava2 adapter just add your adapter like:

```java
retrofitBuilder.addCallAdapterFactory(RxJava2CachedCallAdapterFactory.create(cache));
retrofitBuilder.addCallAdapterFactory(RxJava2CachedCallAdapterFactory.create(context, APP_VERSION));
retrofitBuilder.addCallAdapterFactory(RxJava2CachedCallAdapterFactory.createAsync(cache));
retrofitBuilder.addCallAdapterFactory(RxJava2CachedCallAdapterFactory.createAsync(context, APP_VERSION));
retrofitBuilder.addCallAdapterFactory(RxJava2CachedCallAdapterFactory.createWithScheduler(cache, scheduler));
retrofitBuilder.addCallAdapterFactory(RxJava2CachedCallAdapterFactory.createWithScheduler(context, APP_VERSION, scheduler));
```

Don't forget to include dependency:

dependencies {
    compile 'com.github.iagocanalejas:retrocache-rxjava2:<VERSION>'
}

Pull Requests

I welcome and encourage all pull requests. Here are some basic rules to follow to ensure timely addition of your request:

  1. Match coding style (braces, spacing, etc.) This is best achieved using CMD+Option+L (on Mac) or Ctrl+Alt+L on Windows to reformat code with Android Studio defaults.
  2. Pull Request must pass all tests with gradlew check for styling, and gradlew test for unit tests.
  3. If its a feature, bugfix, or anything please only change code to what you specify.
  4. Please keep PR titles easy to read and descriptive of changes, this will make them easier to merge.
  5. Pull requests must be made against develop branch. Any other branch (unless specified by the maintainers) will get rejected.
  6. Have fun!

Maintained By

IagoCanalejas (@iagocanalejas)

Andy (@ANDYear21)

License

Copyright 2016 IagoCanalejas.

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.
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].