Bucket

A disk cache library for Android.

License

License

GroupId

GroupId

com.github.simonpercic
ArtifactId

ArtifactId

bucket
Last Version

Last Version

1.0.0
Release Date

Release Date

Type

Type

aar
Description

Description

Bucket
A disk cache library for Android.
Project URL

Project URL

https://github.com/simonpercic/Bucket
Source Code Management

Source Code Management

https://github.com/simonpercic/Bucket

Download bucket

How to add to project

<!-- https://jarcasting.com/artifacts/com.github.simonpercic/bucket/ -->
<dependency>
    <groupId>com.github.simonpercic</groupId>
    <artifactId>bucket</artifactId>
    <version>1.0.0</version>
    <type>aar</type>
</dependency>
// https://jarcasting.com/artifacts/com.github.simonpercic/bucket/
implementation 'com.github.simonpercic:bucket:1.0.0'
// https://jarcasting.com/artifacts/com.github.simonpercic/bucket/
implementation ("com.github.simonpercic:bucket:1.0.0")
'com.github.simonpercic:bucket:aar:1.0.0'
<dependency org="com.github.simonpercic" name="bucket" rev="1.0.0">
  <artifact name="bucket" type="aar" />
</dependency>
@Grapes(
@Grab(group='com.github.simonpercic', module='bucket', version='1.0.0')
)
libraryDependencies += "com.github.simonpercic" % "bucket" % "1.0.0"
[com.github.simonpercic/bucket "1.0.0"]

Dependencies

compile (5)

Group / Artifact Type Version
io.reactivex : rxandroid jar 1.0.1
com.google.code.gson : gson jar 2.4
com.android.support » support-annotations jar 23.1.0
com.jakewharton : disklrucache jar 2.0.2
io.reactivex : rxjava jar 1.0.15

Project Modules

There are no modules declared in this project.

Bucket

Logo

Bucket is a disk cache library for Android. You can use it to cache any object that can be serialized to json.

DiskLruCache by Jake Wharton is used as the underlying cache.

Build Status Download

Supported operations:

  • get
  • put
  • contains
  • remove
  • clear

Bucket contains synchronous, async and Rx methods for all operations.

Usage

Add using Gradle:

compile 'com.github.simonpercic:bucket:1.0.0'

Initialize

Create a singleton instance using a builder()

// create a singleton instance using a builder()
int maxSizeBytes = 1024 * 1024;
Bucket bucket = Bucket.builder(context, maxSizeBytes).build();

You can also pass in a custom Gson instance, if you wish to do so:

// create a singleton instance using a builder()
Gson gson = ...
Bucket.builder(context, maxSizeBytes).withGson(gson).build();

Get

// sync
MyObject object = bucket.get("key", MyObject.class);

// async
bucket.getAsync("key", MyObject.class, new BucketGetCallback<MyObject>() {
            @Override public void onSuccess(MyObject object) {
                
            }

            @Override public void onFailure(Throwable throwable) {

            }
        });
        
// Rx
Observable<MyObject> observable = bucket.getRx("key", MyObject.class);

Put

// sync
bucket.put("key", object);

// async
bucket.putAsync("key", object, new BucketCallback() {
            @Override public void onSuccess() {
                
            }

            @Override public void onFailure(Throwable throwable) {

            }
        });
        
// Rx
Observable<Boolean> observable = bucket.putRx("key", object);

Contains

// sync
boolean contains = bucket.contains("key");

// async
bucket.containsAsync("key", new BucketGetCallback<Boolean>() {
            @Override public void onSuccess(Boolean contains) {
                
            }

            @Override public void onFailure(Throwable throwable) {

            }
        });
        
// Rx
Observable<Boolean> observable = bucket.containsRx("key");

Remove

// sync
bucket.remove("key");

// async
bucket.removeAsync("key", new BucketCallback() {
            @Override public void onSuccess() {
                
            }

            @Override public void onFailure(Throwable throwable) {

            }
        });
        
// Rx
Observable<Boolean> observable = bucket.removeRx("key");

Clear

// sync
bucket.clear();

// async
bucket.clearAsync(new BucketCallback() {
            @Override public void onSuccess() {
                
            }

            @Override public void onFailure(Throwable throwable) {

            }
        });
        
// Rx
Observable<Boolean> observable = bucket.clearRx();

Generics / Collections support

Bucket fully supports Generics and Collections by passing a custom Type instance created through Gson:

// generics
public class GenericObject<T> {
    T object;
    String value;
}

Type genericType = new TypeToken<GenericObject<MyObject>>(){}.getType();
GenericObject<MyObject> object = bucket.get("key", genericType);


// collections
Type collectionType = new TypeToken<List<MyObject>>() {}.getType();
List<MyObject> list = bucket.get("key", collectionType);

Dependencies

Bucket depends on the following awesome open source projects:

Why use it?

  • store any kind of object, as long as it is json-serializable
  • relies on RxJava and RxAndroid schedulers for threading
  • supports generics and collections
  • unit and android test coverage
  • checkstyle, findbugs, pmd and lint static code analysis checks

Sample

Check out the androidTest directory for practical examples.

License

Open source, distributed under the MIT License. See LICENSE for details.

Versions

Version
1.0.0