• Stars
    star
    189
  • Rank 204,649 (Top 5 %)
  • Language
    TypeScript
  • Created about 9 years ago
  • Updated over 1 year ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

React Native LRU cache build on top of AsyncStorage

react-native-cache

LRU cache built on top of the React Native communities' AsyncStorage v2 (or included MemoryStore) and automatic pruning of least recently used items.

Installation

  • Run the following command.
npm install --save react-native-cache
  • Import the library.
import { Cache } from "react-native-cache";

Usage

You initialize a cache using the following.

const cache = new Cache({
    namespace: "myapp",
    policy: {
        maxEntries: 50000, // if unspecified, it can have unlimited entries
        stdTTL: 0 // the standard ttl as number in seconds, default: 0 (unlimited)
    },
    backend: AsyncStorage
});

Multiple caches can be mantained in an application by instantiating caches with different namespaces.

Setting a key's value in the cache

await cache.set("hello", "world");
// key 'hello' is now set to 'world' in namespace 'myapp'

Get an item in the cache

const value = await cache.get("key1");
console.log(value);
// 'hello'
});

Getting an item from the cache also moves it to the end of the LRU list: it will be evicted from the cache last.

Delete an item from the cache

await cache.remove("key1");
// 'key1' is no more.

Peeking at an item in the cache

You can also peek at an item in the cache without updating its position in the LRU list:

const value = await cache.peek("key1");
// value is retrieved but LRU value is unchanged.

Getting all of the elements in the cache

You can look at all of the elements in the cache without updating its position in the LRU list:

const entries = await cache.getAll();
console.dir(entries);
// {
//     "key1": { "value": 42 }
//     "key2": { "value": 2 }
//     ...
// }

Clearing all of the elements in the cache

You can also clear all of the items in the cache with:

await cache.clearAll();

For more usage examples, see the tests.

More Repositories

1

react-native-location

React Native plug-in that provides GPS location information
JavaScript
870
star
2

take-home-engineering-challenge

49
star
3

passport-publickey

Public key authentication with signed nonce for passport.
JavaScript
13
star
4

k8s-prom-grafana

Prometheus and Grafana ops code on K8s
Smarty
12
star
5

geotile

XYZ geotile libraries across a variety of languages
JavaScript
4
star
6

topological

Cloud native real time data flow framework
JavaScript
3
star
7

messages-frontend

A simple frontend application sample using ember.js and Yeoman.
JavaScript
3
star
8

rust-reading-list

Rust reading list
3
star
9

ad-analytics-spark

Sample Spark application that combines physical ad locations and location traces to build ad analytics.
Python
2
star
10

ecu-bridge

Sample rust application
Rust
2
star
11

firehose-prototype

Rust
1
star
12

simple-nodejs-server

A very simple node.js server
JavaScript
1
star
13

hueBridge

Hue bridge: searches for lights on the local network and connects them to Nitrogen.
JavaScript
1
star
14

bergen-cli

Bergen makes manage data pipeline configuration easier and cleaner.
1
star
15

cncf-stack

CNCF infrastructure stack
1
star
16

copyData

Simple Kubernetes Native Spark Job
Scala
1
star
17

topological-direct

DirectConnection for topological
JavaScript
1
star
18

fabrikate-spark-operator

Fabrikate component for Spark Operator
1
star
19

rust-crdt-wasm

Rust CRDT WASM
Rust
1
star
20

topological-sample

Simple sample pipeline for Topological
JavaScript
1
star
21

simple-service

very simple service for use as an example with devops scripts
JavaScript
1
star
22

fabrikate-example

Example Fabrikate high level deployment description
1
star
23

rust-webassembly-k3s-krustlet-seed

HTML
1
star
24

terraform-jaeger-operator

Terraform module for a Jaeger operator based deployment of Jaeger
HCL
1
star
25

azure-snack

Spark, node.js, Cassandra, and Kafka on Azure Container Service (SNACK)
Smarty
1
star
26

keda-azure-function

A Helm Chart that parameterizes a deployment of an Azure Function with KEDA
1
star
27

topological-cli

CLI for generating and running Topologies
Go
1
star
28

honeycomb-rust-poc

Honeycomb Rust POC
Rust
1
star
29

fabrikate-cloud-native-manifests

Resource Manifests for Cloud Native stack
1
star
30

elk

Kubernetes ELK support
Smarty
1
star
31

fabrikate-cloud-native-materialized

1
star
32

cloud-native-manifests

1
star
33

viaduct

Viaduct makes managing datasets easier
1
star
34

fabrikate-azure-function

Fabrikate definition for a Azure Function
1
star
35

azure-batch-docker-container

Sample code that executes a docker container under Azure Batch for every file in an input container.
Python
1
star
36

fabrikate-prometheus-grafana

Prometheus grafana component for Fabrikate
1
star
37

heatmap

Sample heatmap generation script for Apache Spark from a location dataset
Python
1
star