留言板

Get a handle on ehcache object?

thumbnail
Andrew Jardine,修改在8 年前。

Get a handle on ehcache object?

Liferay Legend 帖子: 2416 加入日期: 10-12-22 最近的帖子
Hi guys,

I am wondering if someone has done this before and can shed some light for me. I have defined my own custom cache in the liferay-multi-vm-clusered.xml. Using JMX I can see that my cache object is there. I am able to use the MultiVMPoolUtil to put items into this cache and get items out of it -- no problem. I know that when I get a cache with a given name it returns to be a PortalCache object --


public static <k extends serializable, v serializable>
		PortalCache<k, v> getCache(String name) {

		return (PortalCache<k, v>)getMultiVMPool().getCache(name);
	}
</k,></k,></k>


I know by looking at this object that it has a private member variable of type com.sf.ehcache.Ehcache. This private member is set either through the constructor or by using a setter, but there is no getter to get a handle on this variable.

What I would like --

is to get a handle on this member variable, or gain access to it in some other way so that I can use features of the ehcache API. For example, I would like to use the ehcache API to do things like get a count of objects in the map, or to get the list of objects, etc.

Does anyone know if this is possible, and if so, how to do it?
thumbnail
Olaf Kock,修改在8 年前。

RE: Get a handle on ehcache object?

Liferay Legend 帖子: 6403 加入日期: 08-9-23 最近的帖子
This is a suggestion that I'd not do for everyone - you typically know what you do and give the impression of a trained professional who only does this on streets that have been closed for traffic, but it's still hard to push it (cough) out. (cough) reflection? (cough)

Don't quote me on that ;) (To everybody else: There's nothing to see here. Don't try this at home)
thumbnail
Andrew Jardine,修改在8 年前。

RE: Get a handle on ehcache object?

Liferay Legend 帖子: 2416 加入日期: 10-12-22 最近的帖子
LOL Thanks Olaf. I was hoping that was not the only answer of course -- hate to close major arteries for a marathon when the side street right beside run parallel. Sounds like in this case perhaps there may be no parallel road.

While I have your attention though -- do you know why a getter has not been exposed? Security? Performance? avoiding general mayhem?
thumbnail
Olaf Kock,修改在8 年前。

RE: Get a handle on ehcache object?

Liferay Legend 帖子: 6403 加入日期: 08-9-23 最近的帖子
Why isn't it exposed? Add to those options: "nobody has asked for it ever", "nobody's been missing it", "nobody has pullrequested it ever" and "general evil". Then pick one of the reasons (mine or yours) at random. In other words: I don't know - sorry.
thumbnail
Andrew Jardine,修改在8 年前。

RE: Get a handle on ehcache object?

Liferay Legend 帖子: 2416 加入日期: 10-12-22 最近的帖子
Fair enough - in that case perhaps I will issue a PR and wait for rejection ;). Thanks again Olaf -- if I come up with something crafty I'll be sure not to share it emoticon
Sameer Naik,修改在7 年前。

RE: Get a handle on ehcache object?

Junior Member 帖子: 25 加入日期: 10-3-9 最近的帖子
You can use a command line utility like jmxterm if your requirements allows you to do it outside of your code/process.
Otherwise I think JMX API from your code might also get what you want i.e the counts.

-- Sameer