Foren

Get a handle on ehcache object?

thumbnail
Andrew Jardine, geändert vor 8 Jahren.

Get a handle on ehcache object?

Liferay Legend Beiträge: 2416 Beitrittsdatum: 22.12.10 Neueste Beiträge
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, geändert vor 8 Jahren.

RE: Get a handle on ehcache object?

Liferay Legend Beiträge: 6396 Beitrittsdatum: 23.09.08 Neueste Beiträge
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, geändert vor 8 Jahren.

RE: Get a handle on ehcache object?

Liferay Legend Beiträge: 2416 Beitrittsdatum: 22.12.10 Neueste Beiträge
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, geändert vor 8 Jahren.

RE: Get a handle on ehcache object?

Liferay Legend Beiträge: 6396 Beitrittsdatum: 23.09.08 Neueste Beiträge
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, geändert vor 8 Jahren.

RE: Get a handle on ehcache object?

Liferay Legend Beiträge: 2416 Beitrittsdatum: 22.12.10 Neueste Beiträge
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, geändert vor 7 Jahren.

RE: Get a handle on ehcache object?

Junior Member Beiträge: 25 Beitrittsdatum: 09.03.10 Neueste Beiträge
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