java - Guava Cache not expiring after x timeunit when using timed expire -
i'm having issue guava cache not expiring. i'll leave code down below. cache expires 1 write cache again. took javadocs timed expiration should expire x timeunit after writing. appreciated.
private static final cache<uuid, rainbowwrapper> rainbows = cachebuilder.newbuilder() .removallistener(new removallistener<uuid, rainbowwrapper>() { @override public void onremoval(removalnotification<uuid, rainbowwrapper> notification) { coreapi.debug("removing rainbow: " + notification.getkey().tostring()); rainbowwrapper wrapper = notification.getvalue(); (uuid uuid : wrapper.getuuids()) { coreapi.debug("removing entity: " + uuid); bukkit.getworlds().get(0).getentitiesbyclasses(item.class, armorstand.class).stream() .filter(entity -> entity.getuniqueid().equals(uuid)) .foreach(org.bukkit.entity.entity::remove); } } }).expireafterwrite(fade_time, timeunit.seconds).build();
this explained on guava wiki under when cleanup happen?
basically, long not call methods of cache, nothing happens @ all, because impossible without creating own thread cache, undesired , not done automatically guava cache.
if have read accesses cache, may take while removal listener called, because guava assumes read accesses cache should fast, , tries little work possible read accesses, means typically not call removal listeners. if there have been no write accesses time, cache cleanup , call removal listeners @ read access.
note still means expire feature working: expired entries won't returned cache methods. may happen removal listeners called later expect.
if want force timely removal notifications, should call cache.cleanup()
regularly (e.g., separate thread).
if important notified possible when time elapses, use scheduledexecutorservice
, submit tasks instead of relying on cache , removal notifications.
Comments
Post a Comment