Giter Site home page Giter Site logo

akavache's Introduction

Akavache: An Asynchronous Key-Value Store for Native Applications

Akavache is an asynchronous, persistent key-value cache created for writing native desktop and mobile applications in C#. Think of it like memcached for desktop apps.

What does that mean?

Downloading and caching remote data from the internet while still keeping the UI responsive is a task that nearly every modern native application needs to do. However, many applications that don't take the consideration of caching into the design from the start often end up with inconsistent, duplicated code for caching different types of objects.

Akavache is a library that makes common app patterns easy, and unifies caching of different object types (i.e. HTTP responses vs. JSON objects vs. images).

It's built on a core key-value byte array store (conceptually similar to a Dictionary<string, byte[]>), and on top of that store, extensions are added to support:

  • Arbitrary objects via JSON
  • HTTP Requests
  • Fetching and loading Images
  • Securely storing User Credentials

An example - consider Twitter for Mac

When you open Twitter for Mac, you immediately see content, even before the application finishes talking to Twitter. This content is cached, but the pattern of when to refresh the data might be different. For the tweets themselves, the logic might be something like, "Load the cached data, but always fetch the latest data".

However, for the avatar images, you might have logic like, "Always load the cached image, but if the avatar is older than six hours, refresh the image."

In Akavache, the former might be:

var tweets = await BlobCache.UserAccount.GetAndFetchLatest("tweets", DownloadSomeTweets());

And the latter might be something like:

var image = await BlobCache.LocalMachine.GetAndFetchLatest(tweet.AvatarUrl, 
    DownloadUrl(tweet.AvatarUrl), 
    createdAt => DateTimeOffset.Now - createdAt > TimeSpan.FromHours(6));

No (Thread.)Sleep 'till Brooklyn

Akavache is non-blocking, via a library called the Reactive Extensions - any operation that could delay the UI returns an Observable, which represents a future result.

Akavache also solves several difficult concurrency problems that simplify UI programming. For example, in the image above, a naive cache implementation could end up loading the GitHub avatar icon multiple times if the requests were issued at the same time (which is easy to do if you try to load the avatar for each tweet). Akavache ensures that exactly one network request is issued.

akavache's People

Contributors

anaisbetts avatar haacked avatar tclem avatar aroben avatar schacon avatar

Watchers

 avatar

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.