Caching: How to catch content that Expires

Enonic version: 7.0.x
OS: All

We are caching content (in the part-controller), and have an event listener on node.* events to clear cache entries. When we use Scheduling we discovered that the node is not updated, either in master or draft branch. It looks like the contentlib checks if has expired before it returns content. The content stays unaltered in master.

How can we catch that we need to remove content from cache when content expires?

You are right, currently there are no events for scheduling (i.e. publish from and to). I would recommend checking if content is expired when fetching from cache (based on storing this info in the cache), and evict it if has expired.

There will eventually be events for these cases!

This will not work. We will not catch the fact that content has expired before someone tries to get the content. We have multiple pages showing lists of content that can expire. The cache for these pages will still contain references to the expired pages.

We will crate a scheduled job to clear elements that has expired including elements referring to this element.

I hope you will fix this soon. It really makes no sense that expired content still remains in the master branch.
To me this is faulty behaviour.

Why not simply set an expire time for your cached lists to match the expiration (if any) based on items in the list?
It is unlikely that we will remove items from a branch even if it expires, simply due to potential side-effects. I.e. what should happen to child elements if a parent item expires…

Throwing events on expire however will be implemented.

Do you know when this will be implemented (i.e. throwing events); short or long term?

In terms of lib-cache, I don’t think you can set the expire time dynamically.

If 2019 is short term, i would say long term