Typically object caching in Java is managed by the container or framework in use. Occasionally however there is a need to manually cache domain-specific objects, whereby a java.util.Map implementation will not suffice.
Using the popular ehcache framework as an example, the following pattern is typically observed:
public class SomeClass {
private final Cache cache = …
[...]
Posted in Java | Tagged adapter, caching, patterns |
In OSGi using a publisher/subscriber design can be somewhat more complicated that traditional Java environments:
public class SomeBundleActivator implements BundleActivator {
private SomeService service = …
private ServiceRegistration registration;
public void start(BundleContext context) {
registration = context.registerService(SomeService.class.getName(), service, null);
}
…
}
public class AnotherBundleActivator implements BundleActivator {
private [...]