Lucee + Redis or memcached Hibernate second-level-cache

Has anyone successfully used Redis or Memcached as a second-level cache provider within Lucee’s Hibernate scope? I’m working with a group that needs to do so, and before I dive into trying to get either of the (quite old) hibernate-memcached or hibernate-redis libraries compatible with the Hibernate 3.5.5-Final included in Lucee, I figured I’d ask.

Alternatively, is there any way to point to one of Lucee’s configured caches (the Redis plugin worked perfectly!) as a Hibernate 2LC?

Thanks,

Joe

The one tracked in this ticket? [LDEV-1659] - Lucee

Exactly. The issue facing this group is that the end environment is AWS, and the compliance of trying to run a durable/distributed EHCache is unknown. I’d like to get things set up using Elasticache, which supports either Redis (preferable) or memcached (it’ll do). I’ve done this before in Javaland, but it looks to be a big lift for CFML (either Lucee or Adobe), as the Hibernate versions supported are…lower than current.

What I’ve done so far

I’ve jumped in to making a redis adapter (https://github.com/Jongtae/hibernate-redis) compatible with Hibernate 3.5.5 at a compilation level, but I’m stuck on actually loading the region factory. If I set the ormsettings to the class provided, Hibernate gives a class-not-found error (although I can load the JAR and load the class in Lucee). I assume there’s something with OSGI, dependencies, and classloaders within Lucee and its use of hibernate as an extension that I just don’t get/know.

Something I’m wondering

With Lucee providing its super-pluggable caching, has anyone thought about creating a Hibernate 2LC caching provider that basically acts as an adapter to one of these already-defined internal caches? That could make things a lot easier and open up 2LC to getting out of the custom business.

For example, if I’ve got this in an Application.cfc:

this.cache.connections["someRedisCache"] = { stuff }

It’d be really nice to just state this in ormSettings:

ormSettings.cacheProvider = 'org.lucee.hibernate.caching.LuceeCacheProvider'

ormSettings.cacheName = 'someRedisCache'

If that’s possible, I’d be happy to try to help contribute some code to make it so on the Java side…I just know nothing about CFML anymore, much less how to create a Lucee plugin that’d need to grab something (a cache) from inside the current CFML application ‘context’. If I could get bootstrapped on that, adapting the entity and query caching keys etc. to create a Lucee-specific caching provider is something I could dive into.

Joe

I think this might be an idea to contact @Malcolm or @Gert from https://www.rasia.ch/ as they could give you some time with @micstriit to implement this. I can see the config within the core lucee repo but not sure how it would translate to sending caches to GitHub - lucee/extension-hibernate

The change could possibly happen within there as you say.

The relevant code is round here actually: extension-hibernate/HibernateSessionFactory.java at da26629d6cc18a6d61c53f14ad3bc2e4dfc701e9 · lucee/extension-hibernate · GitHub

if(ormConf.secondaryCacheEnabled()){
			if(cacheConfig!=null && cacheConfig.isFile())
				configuration.setProperty("hibernate.cache.provider_configuration_file_resource_path",cacheConfig.getAbsolutePath());
			if(regionFactory!=null || CFMLEngineFactory.getInstance().getClassUtil().isInstaneOf(cacheProvider, RegionFactory.class))
				configuration.setProperty("hibernate.cache.region.factory_class", cacheProvider);
			else
				configuration.setProperty("hibernate.cache.provider_class", cacheProvider);
			
			configuration.setProperty("hibernate.cache.use_query_cache", "true");
	    	
	    	//hibernate.cache.provider_class=org.hibernate.cache.EhCacheProvider
		}
		}