ember-storages
v1.0.0
Published
The default blueprint for ember-cli addons.
Downloads
1
Readme
ember-storages
An ember-cli addon to store data in storages (cache, local, memory, session).
Information
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:
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:
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:
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:
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.
Versioning
We use SemVer for versioning. For the versions available, see the tags on this repository.
Authors
See the list of contributors who participated in this project.
License
This project is licensed under the MIT License - see the LICENSE.md file for details