Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Eclipse Scout » Cache - how to dispose it?
Cache - how to dispose it? [message #1828374] Mon, 08 June 2020 15:54 Go to next message
Darth Bolek is currently offline Darth BolekFriend
Messages: 25
Registered: August 2019
Junior Member
I can remove all the entries from the cache, but how to unregister/dispose it when I am done with it?
Re: Cache - how to dispose it? [message #1828375 is a reply to message #1828374] Mon, 08 June 2020 15:56 Go to previous messageGo to next message
Ivan Motsch is currently offline Ivan MotschFriend
Messages: 154
Registered: March 2010
Senior Member
What cache do you mean? Any example?
Re: Cache - how to dispose it? [message #1828376 is a reply to message #1828375] Mon, 08 June 2020 16:20 Go to previous messageGo to next message
Darth Bolek is currently offline Darth BolekFriend
Messages: 25
Registered: August 2019
Junior Member
By cache I mean ICache created by ICacheBuilder
including client-server and cluster version.

	
...
import org.eclipse.scout.rt.platform.cache.CacheRegistryService;
import org.eclipse.scout.rt.platform.cache.ICache;
import org.eclipse.scout.rt.platform.cache.ICacheBuilder;
import org.eclipse.scout.rt.platform.cache.ICacheValueResolver;
...

private ICache<KeyContexObject, Integer> createCache(ICacheValueResolver<KeyContexObject, Integer> resolver) {
		LOG.entry();
		ICache<KeyContexObject, Integer> result = null;
		
		@SuppressWarnings("unchecked")
		ICacheBuilder<KeyContexObject, Integer> cacheBuilder = BEANS.get(ICacheBuilder.class);
		result = cacheBuilder
				.withCacheId(cacheId)
				.withValueResolver(resolver)
				.build();
		
		return LOG.exit(result);
	}
Re: Cache - how to dispose it? [message #1828413 is a reply to message #1828374] Tue, 09 June 2020 11:51 Go to previous messageGo to next message
Ivan Motsch is currently offline Ivan MotschFriend
Messages: 154
Registered: March 2010
Senior Member
Thank you for the example.

The ICacheRegistryService holds all caches created by ICacheBuild.
The idea of the ICacheRegistryService is that of a "singleton" cache registry.
It hold caches that are not disposed during the platform lifecycle.
Once the Platform is stopped, the ICacheRegistryService is also disposed and its map containing the caches is garbage collected.

So when using ICacheRegistryService it creates a platform scope cache. When using caches that have only a local lifetime I would directly use HashMap, TreeMap etc.

If that functionality is not sufficient you also can subclass and replace the default implementation of ICacheRegistryService as for example

@Replace
public class MyExtendedCacheRegistryService  implements ICacheRegistryService{
...
//add some logic to dispose  individual cache objects.
...
}


Does that help?
Re: Cache - how to dispose it? [message #1828469 is a reply to message #1828413] Wed, 10 June 2020 10:57 Go to previous message
Darth Bolek is currently offline Darth BolekFriend
Messages: 25
Registered: August 2019
Junior Member
Yes, it does help. Thank you for clarification.

I am researching possibilities for caching user/session related data. For example when user logs in, preferences specific for that user are being cached in one place from wherever they are (DB, LDAP, ...) By preferences I mean: roles/permissions, timezone, locale, theme, view specific properties (columns, order), etc. And after log out / session invalidate all of this data needs to be garbage collected.

So, what I am thinking right now is global (CRS registered) ICache<String, UserData> = (user name, user data), each authenticated user(session?) will get its own entry. UserData class will keep all user specific caches (there will be more than one). From what I can tell I should be able to use ICache (BasicCache) without registering it - that is for caches inside UserData class. This way I won't have to worry about unregistering them.

Things to think about:
How to treat user logging in multiple times from different browsers? per user or per session? - the longer I think about it the more I am leaning towards per user option - but that means it will have to be thread safe...

Subclassing/extending is always an option, but first I would like to have good understanding of what I am going to modify.
Previous Topic:Own form widget - close event not fired ?
Next Topic:Scout + JPA. Where is good place to get EntityManager?
Goto Forum:
  


Current Time: Fri Apr 26 16:49:01 GMT 2024

Powered by FUDForum. Page generated in 0.03010 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top