# Find cached methods

**URL:** <https://discuss.emberjs.com/t/find-cached-methods/6383>\
**Category:** Ember Data\
**Created:** [September 30, 2014, 1:50pm UTC](https://discuss.emberjs.com/t/find-cached-methods/6383 "2014-09-30T13:50:23Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![bencolon](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.emberjs.com/bencolon/32/9595_2.png) [@bencolon](https://discuss.emberjs.com/u/bencolon)\
**Post date:** [September 30, 2014, 1:50pm UTC](https://discuss.emberjs.com/t/find-cached-methods/6383/1 "2014-09-30T13:50:23Z")

</div>

I’m working on an application whose a bunch of records are only updated (backend side) **once a day**. It seems totally useless to request the server (via the store) every time the app need to get all these kind of records.

I’ve reopened the DS.Store and added two “find cached” methods with cache expiration options :

- `findAllCached` to get all records
- `findQueryCached` to query some records

Both methods have expiration options :

- `for`, to define an expiration period
- `until`, to define an expiration date

These methods request the server only if records are not yet cached.

`findAllCached` is based on `findAll` and `all` DS.Store methods.

`findQueryCached` is based on `findQuery` method plus a cache system linked to model metadata object.

Examples :

```auto
 this.store.findAllCached("user", { for: moment.duration(1, "hours") });
 this.store.findAllCached("user", { until: moment().add(1, "hours") });

 this.store.findQueryCached("post", { filter: "active" }, { for: moment.duration(1, "hours") });
 this.store.findQueryCached("post", { filter: "active" }, { until: moment().add(1, "hours") });

```

Here is a gist of this draft hack :

[https://gist.github.com/bencolon/7f062cb28d7b82cd2038](https://gist.github.com/bencolon/7f062cb28d7b82cd2038)

And a JsBin with a basic use case. Cars records are cached for one hour VS Trucks records are not cached.

[http://jsbin.com/pogali](http://jsbin.com/pogali)

What you guys are thinking about ? Useless ? Useful ?

Can’t wait to hear the Ember community about that.
