https://github.com/bbvaengineering/ember-storages
An ember-cli addon to store data in storages (cache, local, memory, session)
https://github.com/bbvaengineering/ember-storages
cache ember-addon ember-cli-addon storage
Last synced: 11 months ago
JSON representation
An ember-cli addon to store data in storages (cache, local, memory, session)
- Host: GitHub
- URL: https://github.com/bbvaengineering/ember-storages
- Owner: BBVAEngineering
- License: mit
- Created: 2017-06-13T10:22:43.000Z (over 8 years ago)
- Default Branch: master
- Last Pushed: 2022-12-07T23:24:33.000Z (about 3 years ago)
- Last Synced: 2025-02-25T04:35:06.782Z (12 months ago)
- Topics: cache, ember-addon, ember-cli-addon, storage
- Language: JavaScript
- Homepage:
- Size: 2.79 MB
- Stars: 1
- Watchers: 10
- Forks: 0
- Open Issues: 23
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- Contributing: CONTRIBUTING.md
- License: LICENSE.md
Awesome Lists containing this project
README
# ember-storages
[](https://travis-ci.com/BBVAEngineering/ember-storages)
[](https://badge.fury.io/gh/BBVAEngineering%2Fember-storages)
[](https://badge.fury.io/js/ember-storages)
[](https://david-dm.org/BBVAEngineering/ember-storages)
[](https://codecov.io/gh/BBVAEngineering/ember-storages)
[](https://greenkeeper.io/)
[](https://emberobserver.com/addons/ember-storages)
An [ember-cli addon](http://www.ember-cli.com/) to store data in storages (cache, local, memory, session).
## Information
[](https://nodei.co/npm/ember-storages/)
## Install in ember-cli application
In your application's directory:
ember install ember-storages
## Usage
This service is an overall cache which saves any type of data, by synchronizing them in memory and in localStorage.
In both reading and writing, MemoryStorage takes precedence over LocalStorage.
In the reading, when it is detected that the data has expired, it is deleted.
Example:
```javascript
this.get('cache').set('foo', 'bar');
this.get('cache').get('foo'); // bar
```
It can be used from any file where this service is injected (by default in every routes and controllers).
### Data validity
By default, the validity time of these data is 10 minutes.
We can change this time by passing the amount of minutes or by passing the metadata object:
```javascript
this.get('cache').set('foo', 'bar', moment().add(10, 'minutes')); // 10 min
this.get('cache').set('foo', 'bar', {
expire: moment().add(10, 'minutes'), // 10 min
});
```
### Data structure
The data is saved with the follow structure:
```javascript
foo: {
meta: {
updated: 1429806124, << last updated time
expire: 1429806124 << time of expiration
},
data: "bar"
}
```
'meta.expire' is the timestamp in which time the data will be expired.
'data' is the storaged value.
### Bindings
We can bind a property of controller and a value in cache.
Example:
```javascript
export default Ember.Controller.extend({
foo: Ember.computed.alias('this.cache.foo'),
actions: {
changeFoo() {
this.set('foo', 'bar2');
},
}
...
}
```
## Contribute
If you want to contribute to this addon, please read the [CONTRIBUTING.md](CONTRIBUTING.md).
## Versioning
We use [SemVer](http://semver.org/) for versioning. For the versions available, see the [tags on this repository](https://github.com/BBVAEngineering/ember-storages/tags).
## Authors
See the list of [contributors](https://github.com/BBVAEngineering/ember-storages/graphs/contributors) who participated in this project.
## License
This project is licensed under the MIT License - see the [LICENSE.md](LICENSE.md) file for details