Coder Social home page Coder Social logo

remember's Introduction

Remember

An in-memory data store backed by shared preferences, for Android.

This is a key-value store with some nice properties:

  1. Speed. Everything is loaded into memory so reads can happen on the UI thread. Writes and deletes happen asynchronously (with callbacks). Every public method is safe to call from the UI thread.

  2. Durability. Writes get persisted to disk, so that this store maintains state even if the app closes or is killed.

  3. Consistency. Doing a write followed by a read should return the value you just put.

  4. Thread-safety. Reads and writes can happen from anywhere without the need for external synchronization.

Note that since writes are asynchronous, an in-flight write may be lost if the app is killed before the data has been written to disk. If you require true 'commit' semantics then Remember is not for you.

Usage

Pre-requisite: Your project must have Guava installed. In your app's build.gradle file, add it to your dependencies:

dependencies {
    compile 'com.google.guava:guava:18.0'
}

When your app starts up, initialize Remember. This only has to be done once, and should happen in your app's onCreate():

@Override
public void onCreate() {
    super.onCreate();
    Remember.init(getApplicationContext(), "com.mysampleapp.whatever");
}

(Note that this is the Application-level onCreate(), NOT the Activity onCreate(). Check out the sample app for an example.)

Now you can freely use Remember from anywhere in your app:

Remember.putString("some key", "some value");
String value = Remember.getString("some key");

Sample app

Clone and build this repo in Android Studio to see an example of a sample app. The app simply increments a counter stored in Remember and tells you the value.

Contact

Michael Lapadula: [email protected]

License

Copyright 2015 Tumblr, Inc.

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 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.

remember's People

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.