Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3611860
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T21:55:39+00:00 2026-05-18T21:55:39+00:00

I am trying to migrate my project code from OSCache to EhCache. We have

  • 0

I am trying to migrate my project code from OSCache to EhCache.

We have used OSCache not only as a second-level Hibernate cache provider but also to store other objects of a different nature. They all happily shared the same cache instance without any collisions due to non-overlapping cache keys.

One big difference when moving towards EhCache is that each region has its different cache instance. This is potentially good as it can improve lookup speed as data of the different nature resides separately. Unfortunately, this has a price of configuration hell. Let me explain.

In the OSCache world, I would configure my cache capacity to be, let’s say, 10000. Now if a particular installation would require/could afford more RAM, I would easily beef it up to 50000 and that would do. Now in EhCache I have to go and change the setting by portion of this delta for every region!

Moreover, one installation might have higher usage of objects of type X whereas another installation might prefer higher churn of objects of type Y. We have dozens of installations and each installation would have hundreds of different caches. For this, we would have to hire bunch of people just doing nothing but monitoring cache patterns and tweaking the settings!

I was expecting CacheManager to have some sort of a global cache capacity setting and each internal cache would fight for more capacity, depending on entry usage. However the only way I found to set the cache capacity is via CacheConfiguration which is many-to-one against CacheManager.

So far the only option I can see is to try to force the Hibernate to use one global cache for all the entities. Does anybody know how to do that? Are there any other, better, solutions for my scenario?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-18T21:55:40+00:00Added an answer on May 18, 2026 at 9:55 pm

    You can try having one single cache and adding decorators around it. The decorators can have names matching your region names so that hibernate can use those caches but those decorators would be using the same cache underneath. So theres only one cache config to manage.
    You can achieve this by implementing Custom cache decorators and set up the names of your decorated caches.

    You can have ehcache.xml something like this:

    <defaultCache maxElementsInMemory="10000" eternal="false"
        overflowToDisk="false"/>
    
    <cache name="singleSharedCache" maxElementsInMemory="2000"
        eternal="false" overflowToDisk="false">
        <cacheDecoratorFactory class="com.xyz.util.CustomEhcacheDecoratorFactory"
            properties="name=org.hibernate.tutorial.domain.Person" />
        <cacheDecoratorFactory class="com.xyz.util.CustomEhcacheDecoratorFactory"
            properties="name=org.hibernate.tutorial.domain.Event" />
    </cache>
    

    The “com.xyz.util.CustomEhcacheDecoratorFactory” is a custom ehcache decorator factory class which is used to create the decorated ehcaches. You can use the “properties” attribute to set up the decorated ehcache in any way you want, here you only use a name property to configure the name of the new decorated ehcache. All other operations can be delegated to the underlying cache.

    Providing one custom cache decorator that would work for this use-case here, it reuses the EhcacheDecoratorAdapter that comes in the ehcache jar and just overrides getName(). EhcacheDecoratorAdapter delegates all operations to an underlying ehcache which you pass in the constructor:

    
    package com.xyz.util;
    
    import java.util.Properties;
    
    import net.sf.ehcache.Ehcache;
    import net.sf.ehcache.constructs.CacheDecoratorFactory;
    import net.sf.ehcache.constructs.EhcacheDecoratorAdapter;
    
    public class CustomEhcacheDecoratorFactory extends CacheDecoratorFactory {
    
        public Ehcache createDecoratedEhcache(final Ehcache cache,
                final Properties properties) {
            return new EhcacheDecoratorAdapter(cache) {
                private final String name = properties.getProperty("name");
    
                public String getName() {
                    return name;
                }
            };
        }
    
        public Ehcache createDefaultDecoratedEhcache(final Ehcache cache,
                final Properties properties) {
            return new EhcacheDecoratorAdapter(cache) {
                private final String name = properties.getProperty("name");
    
                public String getName() {
                    return name;
                }
            };
        }
    }
    
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an application that we're trying to migrate to 64bit from 32bit. It's
I'm trying to migrate a website from Windows 2000 to Win2k3 using the IIS
I'm trying to migrate a MySQL-based app over to Microsoft SQL Server 2005 (not
I'm trying to migrate some models ImageFields to using the S3BotoStorage storage backend from
Intro : I'm trying to migrate our Trac SQLite to a PostgreSQL backend, to
I'm trying to migrate a VB6 business object, which uses RDS to be accessed,
I'm in the process of trying to migrate my ASPNET site to Django. All
I'm now trying to migrate wordpress posts to mangoBlog 1.5. But, I can't find
Trying to setup an SSH server on Windows Server 2003. What are some good
Trying to get my css / C# functions to look like this: body {

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.