mikehostetler / amplify

AmplifyJS
http://amplifyjs.com
GNU General Public License v2.0
1.45k stars 144 forks source link

Added ability to override a cache (for amplify.store cache types) #25

Closed instanceofme closed 13 years ago

instanceofme commented 13 years ago

Pass an override: true property in the cache setting, and it will perform the ajax request and replace an existing cache.

Example:

amplify.request( "persist-cache", { cache: { type: "persist", override: true } }, ...

Useful when you perform an action that you know modifies the result of a previously-cached request.

Use case 1: I'm listing a node in a tree. I request the content of the current node, caching the result for 5 minutes. I have a "create node" button that will create a new node inside the current node. Any request for the current node won't show the newly created node until the end of the 5 minutes caching period.

Use case 2: refresh button.

instanceofme commented 13 years ago

Making it work for the _default cache would be painstaking (would require the implementation of the timeout clearing).

My suggestion would be to leave it as is, since it seems to me that explicitly specifying memory as cache type will make use of amplify.store.memory, and thus benefit from the override behavior.

scottgonzalez commented 13 years ago

This breaks the separation of logic. The requestor isn't allowed to know that the data is cached. See http://groups.google.com/group/amplifyjs/browse_thread/thread/bc0794907fe9d64d for a related discussion.