Ehcache-sizeofengine

Configurable sizeOf engine for Ehcache


Project maintained by ehcache Hosted on GitHub Pages — Theme by mattgraham

What is this?

Simply by being on your application's classpath, ehcache-sizeofengine will automagically be picked up by Ehcache. It replaces the SizeOfEngine implementation that ships with Ehcache (2.8.0 onwards) with the EhcacheSizeOfEngine implementation of this project, which lets you control what is then being sized.

Using existing filter configurators

You simply need to add the jars of the modules that you want along side this project's jar

Configuring the Filter yourself

In order to ignore fields or instances of certain classes when sizing object graphs, you'll have to

  1. Create a ServiceLoader project, for net.sf.ehcache.sizeofengine.FilterConfigurator
    • Have your jar contain a text file named META-INF/services/net.sf.ehcache.sizeofengine.FilterConfigurator
    • The file should contain the fully qualified class name of your implementation
  2. Implement FilterConfigurator's configure method to configure the Filter of classes and fields
  3. put your jar on your application's classpath, along side of the ehcache jar and this ehcache-sizeofengine jar
  4. Use Ehcache's Automatic Resource Control for your heap tier

Example

    public static final class StupidConfigurator implements FilterConfigurator {

        @Override
        public void configure(final Filter ehcacheFilter) {
            // Will not size any instance of Number, and given the second arg, no subtype neither
            ehcacheFilter.ignoreInstancesOf(Number.class, false);
        }
    }

There can be as many FilterConfigurator on the classpath as required, they'll have configure the filter once. The Filter is shared across all SizeOfEngine instances created.