eyelidlessness/tasks — pull request #8 by eyelidlessness (2014-02-01 22:09:03+00:00)
Title: LocalCache service

Using `localStorage`, stores JSON representations of values.

Items stored with `LocalCache` will:

- **fail with a return value of `false`** rather than throwing an exception on `LocalCache#put`.

Items stored with `LocalCache` may optionally:

- **expire**, provided an expiration value compatible with [moment's `add` method](http://momentjs.com/docs/#/manipulating/add/).
- **refresh expiration** on retrieval, expiring only after the value has not been accessed for the specified time.

`LocalCache` provides the following methods:

- `get(key)`: Returns the cached value for `key`. If the stored cache value is expected to refresh expiration, the expiration start time will be reset on access.
- `set(key, value, expires, refreshExpiration)`: Stores `value` for the cache `key` (overwriting any previous value). `expires` can be any value compatible with `moment`'s `add` method (all expiration times will be relative to the time of execution). `refreshExpiration` instructs `LocalCache` to restart the expiration clock on each `get` access.
- `unset(key)`: removes the cached value for `key`, failing silently if no such cache is stored.
- `clear()`: removes all values stored in `localStorage`.
- `storageSize()`: returns the calculated size stored in `localStorage`, including the overhead of `LocalStorage` configuration.