@Documented @Retention(value=RUNTIME) @Target(value=METHOD) public @interface Cacheable
For example, this load() method loads some data from the network
and we want it to cache loaded data for 5 seconds (to avoid delays):
@Cacheable(lifetime = 5, unit = TimeUnit.SECONDS)
String load(String resource) throws IOException {
return "something";
}
You can cache them forever, which means that once calculated and cached value will never expire (may be a nice alternative to static initializers):
@Cacheable(forever = true)
String load(String resource) throws IOException {
return "something";
}
Since version 0.7.14 you can also annotate methods that should flush
cache of the object, for example:
public class Page {
@Cacheable
public String get() {
// load data from external source, e.g. the network
return data;
}
@Cacheable.Flush
public void set(String data) {
// save data to the network
}
}public abstract int lifetime
public abstract TimeUnit unit
The minimum unit you can use is a second. We simply can't cache for less than a second, because cache is being cleaned every second.
public abstract boolean forever
Copyright © 2012-2013 jcabi.com. All Rights Reserved.