I don't understand Cache#get in your README.md what syntax is this?
Closed this issue · 9 comments
Hi there,
first of all, thanks for the great module! Next, I don't understand the syntax you specify in your readme:
Cache#get(key[, options])
What is the "#"?
Also, I am trying to find examples for how to update my cache after a delete action on my data is done... I am thinking I should be using .touch operation, but can't find any examples..
Can you help clarify?
Error: CacheFactory.touch is not a function
What is the "#"?
#
it denotes an instance member of a class. .
would denote a static member.
Also, I am trying to find examples for how to update my cache after a delete action on my data is done
You want to remove something from the cache? Use Cache#remove(key)
Thanks for the response, can you please give an example of "it denotes an instance member of a class"?
I am currently caching http requests for a UI view that lists videos in a table.
When a video is added / updated or deleted somewhere in my app, I have to mark the cache as dirty.
For now, i am just destroying the cache for the http key and rebuilding it.
But I noticed you have a "touch" function... unfortunately, I don't know how to use it.
If you are on codementor, I have placed a live help request here: https://www.codementor.io/dashboard#/active-requests/3826997295
Calling Cache#touch
does not mark an item as dirty, it refreshes the item's expiry datetime, making it as if the item has just been re-inserted. If you know an item in the cache is old, remove and refresh it.
Doing cache.touch('some-key')
is the same as doing cache.put('some-key', cache.remove('some-key'))
.
can you please give an example of "it denotes an instance member of a class"?
class Foo {
// Referred to in documentation as Foo.beep
static beep () {}
// Referred to in documentation as Foo#boop
boop () {}
}
Foo.beep(); // Call Foo.beep which is a static member
const foo = new Foo(); // Call Foo#boop which is an instance member
Hi jmdobry,
I see that CacheFactory is a provider which can be injected into controllers, but when I try to inject into "Cache" into services, it says "unknown provider"
how then, can I access "Cache#touch"?
There isn't any provider for Cache
. You create an instance of Cache
by calling createCache
.
angular.module('myApp', ['angular-cache'])
.run(function (CacheFactory) {
var cache = CacheFactory.createCache('my-cache', {});
cache.put('foo', 'bar');
console.log(cache.get('foo')); // "bar"
cache.touch('foo'); // etc.
});
Hi jmdobry, How can I mark the cache as dirty?
What do you mean by "dirty"?
I needed to update my cache when a new user logs in - so I wanted to mark the cache so that it would be replaced with new content instead of retrieving the old content.
But what I ended up doing was just destroyAll
and that seamed to do the trick