# angular-client-cache

> Client side cache with compression in angular

Latest version **1.0.0** (published 2015-04-29) · MIT license · 0 weekly downloads

## Install

```sh
npm install angular-client-cache
pnpm add angular-client-cache
yarn add angular-client-cache
bun add angular-client-cache
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.0 |
| Published | 2015-04-29 |
| First published | 2015-04-26 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 3 |
| Known vulnerabilities | 0 (+10 in 1 direct dependencies) |
| Install scripts | no |
| Author | Jonathan Cairns |
| Maintainers | jonocairns |
| Keywords | cache, localStorage, sessionStorage, browser, storage, compression |

## Links

- npm: https://www.npmjs.com/package/angular-client-cache
- Repository: https://github.com/jonocairns/Intergen.ClientCache
- Issues: https://github.com/jonocairns/Intergen.ClientCache/issues
- npm.io page: https://npm.io/package/angular-client-cache

## Dependencies (3)

- [gulp](https://npm.io/package/gulp.md) ^3.8.11
- [angular](https://npm.io/package/angular.md) ^1.3.15
- [lz-string](https://npm.io/package/lz-string.md) ^1.4.1

## Alternatives

- [memory-cache](https://npm.io/package/memory-cache.md) — 795.0K weekly downloads
- [@httptoolkit/proxy-agent](https://npm.io/package/@httptoolkit/proxy-agent.md) — 11.2K weekly downloads
- [express-cache-controller](https://npm.io/package/express-cache-controller.md) — 5.3K weekly downloads
- [http-cache-middleware](https://npm.io/package/http-cache-middleware.md) — 4.5K weekly downloads
- [cache2](https://npm.io/package/cache2.md) — 1.5K weekly downloads

## Recent versions

- 1.0.0 (latest) — 2015-04-29
- 0.0.7 — 2015-04-27
- 0.0.6 — 2015-04-27
- 0.0.5 — 2015-04-27
- 0.0.4 — 2015-04-26
- 0.0.3 — 2015-04-26
- 0.0.2 — 2015-04-26
- 0.0.1 — 2015-04-26

## README

# angular-client-cache

[![Build Status](https://travis-ci.org/jonocairns/angular-client-cache.svg?branch=master)](https://travis-ci.org/jonocairns/angular-client-cache) [![Code Climate](https://codeclimate.com/github/jonocairns/angular-client-cache/badges/gpa.svg)](https://codeclimate.com/github/jonocairns/angular-client-cache) [![Test Coverage](https://codeclimate.com/github/jonocairns/angular-client-cache/badges/coverage.svg)](https://codeclimate.com/github/jonocairns/angular-client-cache) [![NPM version](https://img.shields.io/npm/v/angular-client-cache.svg?style=flat-square)](https://npmjs.org/package/angular-client-cache) [![License](http://img.shields.io/npm/l/angular-client-cache.svg?style=flat-square)](LICENSE) [![Dependency Status](http://img.shields.io/david/jonocairns/angular-client-cache.svg?style=flat-square)](https://david-dm.org/jonocairns/angular-client-cache)


Local storage and $cacheFactory wrapper for angular. Also has functionality to compress items to be stored in local storage.

Assists with the issue of low (2.5-10MB~) storage limits. Example case - had 5.12MB of localStorage data - this was compressed to 500kb.

Tests run across the lastest versions of IE/Firefox/Chrome

Uses http://caniuse.com/#search=web%20storage

Written in typescript

##Get Started

**(1)** Grab the **npm** package
```bash
$ npm install lz-string angular-client-cache --save
```
or grab the **bower** package
```bash
$ bower install angular-client-cache --save
```

**(2)** Include `angular-client-cache.js` from the [dist](https://github.com/jonocairns/angular-client-cache/tree/master/dist/bin) and `lz-string.js` in your `index.html` after angular.

**(3)** Add `'ClientCache'` to your main module's list of dependencies.

**(4)** Inject 'ClientCacheService' and use it!

Usage info:
```javascript
      set(key: string, value: any): void;

      get<T>(key: string): T;

      tryGetSet<T>(key: string, apiCall: Function, objectBuilder?: Function): ng.IPromise<T>;

      configure(options: IStorageOptions): void;

      remove(key: string): void;

      removeAll(): void;
```

Example usages:
(note: the enum StorageType can only be used if you are using typescript - the values for pure js are Local - 0, Session - 1 and All - 2)
````javascript
    //set:

    var value = 'storeMePlz';
    clientCache.set('key', value);

    //get:

    clientCache.get('key');

    // tryGetSet - this will attempt to get the value from the $cacheFactory, if the value doesn't exist it will perform the API call you supply - then set that response in local/$cacheFactory storage. You can optionally add a builder to build the object from the response.

    clientCache.tryGetSet('key', $http.get('/api/blah'));

    // or

    var builder = function(itemToBuild) { return { something: new Date(itemToBuild.date); }};
    clientCache.tryGetSet('key', $http.get('/api/blah'), builder);

    // configure

    clientCache.configure({ useCompression: true });

    // remove

    clientCache.remove('key');

    // removeAll

    clientCache.removeAll();
```

Options:
``` javascript
    storagePrefix?: string;
    useCompression?: boolean;
```

Dependencies:

LZ-string (https://github.com/pieroxy/lz-string/),
Angular

---
_Source: https://npm.io/package/angular-client-cache · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
