Disabling cache for a bundle

Caching bundle saved or read by Higson Persistence may be configured in three different ways.

1. Automatically generated EhCache#

If cache is not configured on sight then Higson Persistence creates its own EhCache with the name : gmo and idleTime=10 minutes

2. Use selected EhCache region#

You may configure it to use selected EhCache region

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
@Profile("!nocache") //turn off nocache profile
@Bean(destroyMethod = "destroy")
public HigsonPersistenceFactory cacheableHigsonPersistenceFactory() {
	HigsonPersistenceFactory factory=new HigsonPersistenceFactory();
	factory.setDataSource(gmoDataSource);
	factory.setHigsonDataSource(runtimeDataSource);
	factory.setDefaultProfile(env.getProperty("higson.profile"));
	factory.setAutoStartWatchers(true);
	factory.setHiloSequenceName("hp_seq");
	factory.setHiloAllocationSize(100);
	factory.setBundleTable("hp_bundle");
	factory.setBundleColumn("bundle_id");
	factory.setOwnerColumn("owner_id");
	factory.setOwnerPropertyColumn("owner_prop");

	factory.setCacheName("abc") // execute it during Higson Persistence configuration

	return factory;
}
  • if it is defined ehcache “abc” then it uses that
  • if it is not defined ehcache, then it will create ehcache with name “abc” in default configuration

3. Add your own implementation#

On HigsonPersistanceFactory may add your own implementation of cache (based on map or other cache) using HigsonPersistanceFactory.setCache(BundleCache) method

If you want to turn the cache off (for example for testing purposes) you need to give your cache implementation like follow:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
public class NoBundleCache implements BundleCache {

	@Override
	public Bundle get(long id) {
		return null;
	}

	@Override
	public void put(Bundle bundle) {}

	@Override
	public void remove(long id) {}

	@Override
	public void clear() {}
}

@Profile("nocache") //turn on nocache profile
@Bean(destroyMethod = "destroy")
public HigsonPersistenceFactory noCacheHigsonPersistenceFactory() {
	HigsonPersistenceFactory factory = new HigsonPersistenceFactory();
	factory.setDataSource(gmoDataSource);
	factory.setHigsonDataSource(runtimeDataSource);
	factory.setDefaultProfile(env.getProperty("higson.profile"));
	factory.setAutoStartWatchers(true);
	factory.setHiloSequenceName("hp_seq");
	factory.setHiloAllocationSize(100);
	factory.setBundleTable("hp_bundle");
	factory.setBundleColumn("bundle_id");
	factory.setOwnerColumn("owner_id");
	factory.setOwnerPropertyColumn("owner_prop");

	factory.setCacheName("abc");
	factory.setCache(new NoBundleCache()); //setting custom cache implementation

	return factory;
}