Skip to content

Proxying

Alexander Kochurov edited this page Jul 25, 2015 · 2 revisions

###What for? Sometimes the user of your class may want to save the result returned by the cached method. In this case caching efficiency drops dramatically, because even when you remove the object from the cache, it is not collected by GC, because the reference to this object will still remain outside of your cache.

To avoid this, MxCache allows to return the proxy which can "lose" a reference to the object when it decides necessary (for example, if the object is not yet in cache) instead of an actual object,.

###How? Annotate the method (either cached or not)

@UseProxy(class.factories.Proxy.class)

For cached methods proxy factory class can be specified in mxcache.xml through use.proxy parameter.

###Standard types of proxy Mxcache has a standard factory proxy WeakProxyFactory. It creates a proxy containing weak (weak) reference to the calculated element. If by the time of invoking the method the proxy reference is lost, the object will be restored by calling the original method.

For example, if it is assumed that the result of the cached method can be saved by the user, then it is rational to return to him such a proxy, so that while deleting the original object from the cache, the memory held by it would be released.

Clone this wiki locally