Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is $cacheFactory?

I can find absolutely no information on what exactly $cacheFactory is and how it can be useful in your application.

The Angular Documentation says

"Factory that constructs cache objects and gives access to them." -- $cacheFactory

Well, that wasn't at all helpful, what does that mean? There doesn't seem to be anything on Google either.

Can someone please explain What it is & When can it be useful.

Thanks in advance.

like image 744
iConnor Avatar asked Aug 08 '26 04:08

iConnor


1 Answers

Oh the $cacheFactory is simple as i understand it :

If you have a request to retrieve constant data for example like a list of cities.

It's not a good pattern to get this list from the server each time the user go on a form where he has to select a city !

So you have to cache this list. The cacheFactory is done for that !

If you're using $http instead of $resource you can enbale the cache just like that :

$http.get('myUrl', { cache: true })
like image 191
Thomas Pons Avatar answered Aug 11 '26 12:08

Thomas Pons