A simple EhCache3 based EventLogger

If you are using EhCache3 and need to know when a cache entry is created, updated etc. you can implement a simple EventLogger like this:

public class EventLogger implements CacheEventListener<Object> {
    
    private static final Logger LOG = LoggerFactory.getLogger(EventLogger.class);

    @Override
    public void onEvent(CacheEvent event) {
        if (LOG.isDebugEnabled()) {
            LOG.debug("CacheEvent {} with key {}", event.getType(), event.getKey());
        }
    }
}

Now you include the EventLogger in the ehcache.xml:

<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://www.ehcache.org/v3"
    xsi:schemaLocation="http://www.ehcache.org/v3 http://www.ehcache.org/schema/ehcache-core-3.0.xsd">

    <cache-template name="default">
        <listeners>
            <listener>
                <class>de.engelh.EventLogger</class>
                <event-firing-mode>ASYNCHRONOUS</event-firing-mode>
                <event-ordering-mode>UNORDERED</event-ordering-mode>
                <events-to-fire-on>CREATED</events-to-fire-on>
                <events-to-fire-on>UPDATED</events-to-fire-on>
                <events-to-fire-on>EXPIRED</events-to-fire-on>
                <events-to-fire-on>REMOVED</events-to-fire-on>
                <events-to-fire-on>EVICTED</events-to-fire-on>
            </listener>
        </listeners>
    </cache-template>
    
    <cache alias="someCache" uses-template="default">
	...
    </cache>

</config>
a mac and glasses

A Less Mixin for JSF 2 Resource Handling

JSF 2.0 introduced it’s own resource handling. One of the disadvantages of this solution is, that referring to an images inside your CSS doesn’t work the common way:

.foo {
    background-image: url('images/logo.gif'); // doesn't work with JSF 2.x
}

You need to use expression language like:

.foo {
    background-image: url("#{resource['images/logo.gif']}");
}

Now if you are using LESS and don’t want to write this expression over and over again—you need a mixin:

.background-image(@filename) {
    background-image: e(%("url(#{resource['images:%s']})", @filename));
}