[jboss-user] [JBoss Cache: Core Edition] - snippet of code for eviction policy
syreo
do-not-reply at jboss.com
Wed May 27 03:57:02 EDT 2009
Hello,
I am using Jboss cache and i having some issues configuring the eviction policy...
I am not using the xml configuration file, i want to do it programmatically.
The problem is, i haven't found neither in the user guide, nor in the javadoc, an example of code that explain how to configure an eviction policy...
For instance, i want to use the expiration algorithm on a node so this one is evict 2 seconds after being created.
I used this:
| CacheFactory cacheFactory = new DefaultCacheFactory();
| Configuration config = new Configuration();
| Cache cache = cacheFactory.createCache(config);
|
| Fqn fqn = Fqn.fromString("/foo/bar");
| ExpirationAlgorithmConfig eac = new ExpirationAlgorithmConfig();
| eac.setTimeToLive(2L, TimeUnit.SECONDS);
| eac.setExpirationKeyName(ExpirationAlgorithmConfig.EXPIRATION_KEY);
| EvictionRegionConfig erc = new EvictionRegionConfig(fqn, eac);
|
| Region region = cache.getRegion(fqn, true);
| region.setEvictionRegionConfig(erc);
| EvictionConfig ec = new EvictionConfig(erc);
| cache.getConfiguration().setEvictionConfig(ec);
|
| Long future = new Long(System.currentTimeMillis() + 2000);
| cache.getRoot().addChild(fqn).put(ExpirationAlgorithmConfig.EXPIRATION_KEY, future);
|
| boolean shouldbetrue = cache.getRoot().hasChild(fqn);
| System.out.println(shouldbetrue);
|
| Thread.sleep(5000);
|
| boolean shouldbefalse = cache.getRoot().hasChild(fqn);
| System.out.println(shouldbefalse);
I used the code from the user's guide (10.4.5) but there are quite a bunch of object to set properly i guess in order for this snippet to work (ExpirationAlgorithmConfig, EvictionRegionConfig, Region, EvictionConfig...)
I really don't know how to do this...
Thanks for your help!
View the original post : http://www.jboss.org/index.html?module=bb&op=viewtopic&p=4233486#4233486
Reply to the post : http://www.jboss.org/index.html?module=bb&op=posting&mode=reply&p=4233486
More information about the jboss-user
mailing list