views:

13

answers:

1

When using Ehcache with Hibernate, is there a way to specify region names with wildcards in the ehcache.xml file?

For example, to allow for cache settings at the package level (with * as a wildcard indicator) where the given setting is applied to any region that matches the wildcarded name:

<cache name="com.example.my.package1.*" ... />
<cache name="com.example.my.package2.*" ... />

(Note: The package-level distinction is just an example. My question is to wildcards in the general case.)

A: 

Technically, nothing prevent you from using a wildcard in the name attribute of the cache element. After all, it's just a key as reminded in the documentation:

Sets the name of the cache. This is used to identify the cache. It must be unique.

Will this produce the expected result? I'm not sure. As I said, it's just a key so if the idea is that Hibernate will use the region com.example.my.package1.* for a class com.example.my.package1.Foo, this won't happen automatically, you'll have to tell Hibernate to do so (the default is to use the class name for the region).

In other words, using a wildcard won't do nothing more than defining a region with a wildcard in its name.

Pascal Thivent
The question is if I can specify a <cache /> setting in ehcache.xml with a wildcard operator such that the setting is applied to all regions that match the wildcarded name, not if I can have a name that happens to include an asterisk.
@bkent314 I perfectly understood the question and I suggest re-reading my answer: using a wildcard won't produce the result you expect, it will just define the name of a unique cache, nothing more.
Pascal Thivent