Caching for longer duration

We have a requirement for caching data which may not change very frequently. During our design discussions, a suggestion came to cache the data forever, until explicitly "clear cache" management api is invoked.

After going through Cache Internals documentation, I have some questions:

1) If no expiry configurations are specified in PopulateCache or ResponseCache policies, will the cache entry automatically get stored in L2 cache?

2) If yes, will the entry get removed from L2 cache due to any reason or after some specific duration?

3) Is it recommended to have a cache entry persisted for very long duration? In other words, are there any performance implications to be considered?

Solved Solved
0 5 522
1 ACCEPTED SOLUTION

Hi @Sonal,

Here are some answers:

1) If no expiry configurations are specified in PopulateCache or ResponseCache policies, will the cache entry automatically get stored in L2 cache?

If the object is stored in cache, it will always be stored in L2 cache with one exception -- the object needs to be 512K or smaller. L2 has a size cap and anything larger than 512K will not be stored in L2. Nevertheless, just set the expiry time (in seconds) to one week. Why go longer than that?

2) If yes, will the entry get removed from L2 cache due to any reason or after some specific duration?

The cached object will be removed once the expire time hits or you clear out the cache via the management API, Management UI, or InvalidateCache policy.

3) Is it recommended to have a cache entry persisted for very long duration? In other words, are there any performance implications to be considered?

I touched on this question above. I'm not aware of any performance issues as L2 is just storing the data in Cassandra, but why cache objects beyond a few days or one week? Is there a specific use case? If you need to cache longer than that, then maybe it would be good to consider BaaS or KVM and cache data from there daily or weekly.

If my answers helped, please click accept!

View solution in original post

5 REPLIES 5

Not applicable

@Sonal ,

What size of data we are talking here? Size of is data is critical for Caching to be effective.

In this scenario, I would suggest to store data in persistent data storage (e.g. KVM, external data storage) and cache it as required. For example, If you need whole data to be cached then first call can fetch data from data storage and then cache it for rest of the durarion e.g. 24 hours or so.

At this point we are assuming the size of data should be within 512 KB limit of L2 cache, but final value is still being worked upon. We will review your suggestion of persistent data storage. Thanks for your reply.

Hi @Sonal,

Here are some answers:

1) If no expiry configurations are specified in PopulateCache or ResponseCache policies, will the cache entry automatically get stored in L2 cache?

If the object is stored in cache, it will always be stored in L2 cache with one exception -- the object needs to be 512K or smaller. L2 has a size cap and anything larger than 512K will not be stored in L2. Nevertheless, just set the expiry time (in seconds) to one week. Why go longer than that?

2) If yes, will the entry get removed from L2 cache due to any reason or after some specific duration?

The cached object will be removed once the expire time hits or you clear out the cache via the management API, Management UI, or InvalidateCache policy.

3) Is it recommended to have a cache entry persisted for very long duration? In other words, are there any performance implications to be considered?

I touched on this question above. I'm not aware of any performance issues as L2 is just storing the data in Cassandra, but why cache objects beyond a few days or one week? Is there a specific use case? If you need to cache longer than that, then maybe it would be good to consider BaaS or KVM and cache data from there daily or weekly.

If my answers helped, please click accept!

Hi Robert,

Thanks for the detailed answer. The reason behind expiry time longer than a week is because we expect the values to change once a month maybe. So, we were considering retaining cache for longer.

I am not sure I understand your suggestion using BaaS. Probably, I will read through some apigee documents to find more information around it.

We are also considering using a persistent storage outside apigee scope, based on your reply.

Hi @Sonal,

I wasn't trying to suggest caching for one month is a bad idea. It may very well be appropriate for your use case. Additionally, it seems caching for longer periods is acceptable. The previous spec stated up to one year. HTTP 1.1 Spec. Now they recommend to use "what is sensible."

However, what I was trying to promote is to think through the solution/design a bit an ensure it makes sense. We haven't discussed what types of objects you are caching and the underlying service (or db, etc..) so it's challenging to specify something specific. However, we do have BaaS and KVM to help with certain use cases so just wanted to help out with something to look into..

Wish you luck on your Apigee work!