Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Always get error , Cache name contains illegal chars: '<', name="TaxCalculatorInstance.<clinit>.47" #47

Closed
liuhongze opened this issue Apr 14, 2016 · 2 comments
Milestone

Comments

@liuhongze
Copy link

liuhongze commented Apr 14, 2016

Hi, I am trying to create a static field in my class Test.java as this,

public static Cache<String,String> idCache = CacheBuilder.newCache(String.class, String.class).build();

But when I create an instance of Test.java, I got the exception.

Caused by: org.cache2k.impl.CacheUsageExcpetion: Cache name contains illegal chars: '<', name="TestInstance. < c l init > .47"
at org.cache2k.impl.CacheManagerImpl.checkName(CacheManagerImpl.java:130)

I need to share this cache among all the instances of Test.java. So, I use static.

I am confused now, not sure did I use Cache2K incorrectly ?

@cruftex
Copy link
Member

cruftex commented Apr 15, 2016

Short version:

To solve your problem add .name(Test.class) before build().

Long version:

Each cache needs to have a unique name for various organizational reasons, e.g. additional configuration that could be applied, registering the cache with JMX, listing active caches for debugging, etc.

But for testing, or, if you have a very simple application, there is actually not much use to
give every cache a proper name. For that reason there is some code in cache2k that derives
a useful name internally. This code fails for your example, if the cache is constructed in the
class constructor.

As a matter of coincidence I realized that problem yesterday also:
2a18b44

@cruftex cruftex added this to the v0.25 milestone Apr 15, 2016
@cruftex
Copy link
Member

cruftex commented Apr 15, 2016

Added a unit test. Your example will work, without setting a name explicitly, in the next release.
However, always setting a proper name is a good idea, so you can identify your caches.

Thanks for the bug report!

BTW:
I am aware of that starting with cache2k is pretty hard, since the documentation is pretty much non existent. Currently I am improving the JavaDocs and will start to write on a introduction document the next days. Feel free to ask more questions here or on stackoverflow as soon as you get stuck.

@cruftex cruftex closed this as completed Apr 15, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants