EventListener for PortalCache in liferayEventListener for PortalCache in liferayhttps://liferay.dev/en/c/message_boards/find_thread?p_l_id=119785333&threadId=1180851142024-03-28T16:21:33Z2024-03-28T16:21:33ZRE: EventListener for PortalCache in liferayDavid H Nebingerhttps://liferay.dev/en/c/message_boards/find_message?p_l_id=119785333&messageId=1181147672019-12-18T14:25:05Z2019-12-18T14:25:05Z<html><head></head><body>The default in an unconfigured cache is zero. But Liferay includes a <defaultCache /> tag which resets all of these normal defaults:<br><br><pre><code><defaultcache eternal="false" maxelementsinmemory="10000" overflowtodisk="false" timetoidleseconds="600">
</defaultcache></code></pre><br><br><br>So the info in the docs is correct, by I am also correct.<br><br>And, FYI, an eternal cache is a bad idea. Everything you store in the cache takes runtime memory, limiting your capacity and available resources. Caching is meant to alleviate heavy hits on a slow data sink, it is not meant to just hold things around forever. Not sure what you are trying to do with your eternal cache, but I am sure there are much better ways to deal with this information.</body></html>David H Nebinger2019-12-18T14:25:05ZRE: EventListener for PortalCache in liferaykesu kshttps://liferay.dev/en/c/message_boards/find_message?p_l_id=119785333&messageId=1181123762019-12-18T06:34:46Z2019-12-18T06:34:46Z<html><head></head><body>Hi David,Ecache document says setting the <pre><code>eternal</code></pre> attribute, when set to “true”, overrides <pre><code>timeToLive</code></pre> and <pre><code>timeToIdle</code></pre> so that no expiration can take place.Even i have set timeToIdleSeconds="0" so that cache never expires.But still after some time cache is getting cleared there is no pattern so i was trying to find our which event is getting trriggerd.<ul style="list-style: disc outside;"><li>timeToIdleThe maximum number of seconds an element can exist in the cache without being accessed. The element expires at this limit and will no longer be returned from the cache. The default value is 0, which means no timeToIdle (TTI) eviction takes place (infinite lifetime).</li></ul></body></html>kesu ks2019-12-18T06:34:46ZRE: EventListener for PortalCache in liferayDavid H Nebingerhttps://liferay.dev/en/c/message_boards/find_message?p_l_id=119785333&messageId=1181035232019-12-17T14:35:14Z2019-12-17T14:35:14ZIf you don't specify timeToIdleSeconds, it inherits the default which is 10 minutes.<br /><br />If you had started with this question earlier, we probably could have helped you avoid trying to build out all of this code...David H Nebinger2019-12-17T14:35:14ZRE: EventListener for PortalCache in liferaykesu kshttps://liferay.dev/en/c/message_boards/find_message?p_l_id=119785333&messageId=1180986262019-12-17T05:50:09Z2019-12-17T05:50:09ZHi David,I am storing some values in cache with the cache settings as below eternal="true" .But after some time cache values are getting cleared so i want to know the root cause for this<br /> <cache<br /> eternal="true"<br /> maxElementsInMemory="100000"<br /> name="XXXX"<br /> overflowToDisk="false"<br /> ><br /> </cache>kesu ks2019-12-17T05:50:09ZRE: EventListener for PortalCache in liferayDavid H Nebingerhttps://liferay.dev/en/c/message_boards/find_message?p_l_id=119785333&messageId=1180913162019-12-16T14:51:32Z2019-12-16T14:51:32ZThe bigger question is why you are trying to do this...David H Nebinger2019-12-16T14:51:32ZEventListener for PortalCache in liferaykesu kshttps://liferay.dev/en/c/message_boards/find_message?p_l_id=119785333&messageId=1180851132019-12-16T06:01:07Z2019-12-16T06:01:07ZHi <br /><br />I want to write event listners for liferay default Ecache on events like on removal ,on expire.I have implemented PortalCacheListener and overrided the methods but none of the methods are getting called on add/removal of cache objects? whats the correct way to override these events hooks or portlet?<br />public class PortalCacheEventListener implements PortalCacheListener {<br /> @Override<br /> public void dispose() { }<br /> @Override<br /> public void notifyEntryEvicted(PortalCache portalCache, Serializable key, Object value, int timeToLive)<br /> throws PortalCacheException {<br /> System.out.println("notifyEntryEvicted**********key******"+key+"****value****"+value+"********timeToLive******"+timeToLive); } <br /> @Override<br /> public void notifyEntryExpired(PortalCache portalCache, Serializable key, Object value, int timeToLive)<br /> throws PortalCacheException {<br /> System.out.println("notifyEntryExpired**********key******"+key+"****value****"+value+"********timeToLive******"+timeToLive); <br /> @Override<br /> public void notifyEntryPut(PortalCache portalCache, Serializable key, Object value, int timeToLive)<br /> throws PortalCacheException {<br /> System.out.println("notifyEntryPut portalCache.getPortalCacheName()"+portalCache.getPortalCacheName());<br /> System.out.println("notifyEntryPut**********key******"+key+"****value****"+value+"********timeToLive******"+timeToLive);<br /> } <br /> @Override<br /> public void notifyEntryRemoved(PortalCache portalCache, Serializable key, Object value, int timeToLive)<br /> throws PortalCacheException {<br /> System.out.println("notifyEntryRemoved**********key******"+key+"****value****"+value+"********timeToLive******"+timeToLive);<br /> } <br /> @Override<br /> public void notifyEntryUpdated(PortalCache portalCache, Ser