This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
The moose likes EhCache and the fly likes Ehcache and cache names containing a slash Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Caching » EhCache
Bookmark "Ehcache and cache names containing a slash" Watch "Ehcache and cache names containing a slash" New topic
Author

Ehcache and cache names containing a slash

Migrated From Jforum.net
Ranch Hand

Joined: Apr 22, 2012
Posts: 17424
Ehcache has a bug that causes FileNotFoundExceptions when a cache has a name containing a slash (like "sessions/userId") and overflowToDisk="true". The problem is that the cache's data and index file paths are created from its name without any escaping of illegal characters.

Does anyone know a workaround besides overflowToDisk="false"?
[originally posted on jforum.net by sbridge]
Migrated From Jforum.net
Ranch Hand

Joined: Apr 22, 2012
Posts: 17424
I have a problem like that, but i think isn't the same.
I get an error when i try use EhCache:
..........
ERROR [ExceptionWriter ] java.lang.IllegalArgumentException: Cache name cannot contain '/' characters.
........

I don't know what's the problem?
[originally posted on jforum.net by feusebio]
Migrated From Jforum.net
Ranch Hand

Joined: Apr 22, 2012
Posts: 17424
I think the EhCache XML config file parser actually validates the cache name unlike the API which has a minimum of validation (probably to optimize execution times), hence the IllegalArgumentException.

Download the JForum source code and go through all the classes listed in "cacheable.objects" property of your SystemGlobals file. Remove any slashes from the FQN static final fields. This will solve your problem. Or you can implement your own CacheEngine to translate the cache names first. In both cases, the name used in the EhCache config will be the new or translated version.

[originally posted on jforum.net by sbridge]
Migrated From Jforum.net
Ranch Hand

Joined: Apr 22, 2012
Posts: 17424
I fix it with a simple modification at net.jforum.SessionFacade.java class, at the bigining of class in the declaration var section, where we have:

private static final String FQN_LOGGED = FQN + "/logged";
private static final String FQN_COUNT = FQN + "/count";
private static final String FQN_USER_ID = FQN + "/userId";

i put:

private static final String FQN_LOGGED = FQN + "_logged";
private static final String FQN_COUNT = FQN + "_count";
private static final String FQN_USER_ID = FQN + "_userId";

but now i have a problem, some template vars don't have value after login, like us.isAdmin.
[originally posted on jforum.net by feusebio]
Migrated From Jforum.net
Ranch Hand

Joined: Apr 22, 2012
Posts: 17424
Have you checked your log file to see if the missing vars are the result of an exception thrown before they can be set?

I suspect that you will need to correct the FQNs in ForumRepository too.

[originally posted on jforum.net by sbridge]
Migrated From Jforum.net
Ranch Hand

Joined: Apr 22, 2012
Posts: 17424
Hi sbridge,

Do you have Jforum run with EhCache?
I have some dificulties to fix my problem, i correct the FQNs in ForumRepository too, but the forum after a sucess login get undefined value for
"us.isAdmin" at forum_list.html template file:
-------------------------------------
<#list userSessions as us>
<#if us.isAdmin()>
<#assign color = adminColor/>
..........................
</#list>
------------------------------------------

When i use the DefaultCache of Jforum, i don't have this problem, only just for EhCache.

Thanks
[originally posted on jforum.net by feusebio]
Migrated From Jforum.net
Ranch Hand

Joined: Apr 22, 2012
Posts: 17424
net.jforum.repository.TopicRepository also has a FQN containing a slash. It is the last one besides the two you have already fixed.

My solution was to implement my own net.jforum.cache.CacheEngine which replaces all '/' with '.' in the fqns. A ConcurrentMap is used to cache the translations for faster lookup. It is a very custom class created for my own unique requirements (JForum has to work with other code that also wants to configure/start/stop EhCache) so you should write your own. It seems to work but has not been tested under heavy load nor has every page/template been tested.


[originally posted on jforum.net by sbridge]
Migrated From Jforum.net
Ranch Hand

Joined: Apr 22, 2012
Posts: 17424
I try implement EhCache in a fresh Jforum source, but i get same problem with undefined value for expression "is.Admin" in the forum_list.htm file template. And i fix the problem for cache name with slashes, but the problem with undefined expression, seams that it is something with session. The error appear only when user do login and get logged.
[originally posted on jforum.net by feusebio]
Migrated From Jforum.net
Ranch Hand

Joined: Apr 22, 2012
Posts: 17424
I'm getting "Expression us.isAdmin is undefined" with Ehcache even with overflowToDisk="false" and with all slashes replaced. Anyone has the solution?

Pino

[originally posted on jforum.net by Pino.OW]
 
 
subject: Ehcache and cache names containing a slash
 
Similar Threads
[EHCACHE] Problem defaultCache and cache in distributed environment
EhCache and JCS throws Out of Memory error.
ehcache.xml file I have in my ejb app is not used
Caching
Error during CacheManager initialization for distributed ehcache implementation