user1295643
user1295643

Reputation:

Is their any size limit to AngularJS $cacheFactory?

Should I be considering flushing the cache from time to time? Or I can cache all my API responses?

Upvotes: 0

Views: 1600

Answers (2)

ste2425
ste2425

Reputation: 4766

Looking at the source the cache is simply an object. You provide a key and value and it add a property to that object by your key assigning it the value.

This can be seen here

The docs state that you can provide an options object to the $cacheFactory call specifying a capacity parameter turning it into a LRU cache. Meaning if the capacity is met the last recently used cache is removed.

If you do not provide a capacity then Number.MAX_VALUE is used, see here.

So in summary yes. It either user imposed when creating the cache or according to MDN the largest number available to JavaScript.

The MAX_VALUE property has a value of approximately 1.79E+308.

Upvotes: 3

Prasanth-Ramanathan
Prasanth-Ramanathan

Reputation: 74

1. Should I be considering flushing the cache from time to time?

No. Because $cacheFactory will destroy all the data once the session has been closed. Or if you want to flush manually then you can use destroy method.

destroy() - Removes references to this cache from $cacheFactory.

removeAll() - Removes all cached values.

2. I can cache all my API responses?

This is possible in two ways as follows.

  1. $localStorage - If your goal is to store client-side and persistent data.
  2. $cacheFactory - Data exist only for current session.

Upvotes: 1

Related Questions