Backend API. Server-side code: this runs in a Codename One backend, not in the app on the device.

@Retention(CLASS) @Target({METHOD})

public @interface Cacheable

Answers a call from the cache when the cache holds an answer for its key, and otherwise runs the method and keeps what it returned – Spring’s @Cacheable.

@Cacheable(value = "products", key = "#id")
public Product product(long id) { ... }

The build rewrites the method: there is no proxy, so a call from inside the same class is cached too, which Spring’s proxy would skip. The key expression is compiled when the application is built, and one the build cannot compile fails the build. It may name a parameter (#id, or #p0/#a0 by position), a property of one (#user.id, read through its getter or public field), a quoted literal ('all'), #root.methodName, and join them with +. Empty means every parameter, as Spring’s SimpleKeyGenerator keys.

The value is kept in the server’s key/value store – Redis once cn1.kv.url names one, so every process shares it – written as JSON by a codec the build generates for the return type. A null result is not kept, as Spring keeps none with unless = "#result == null". How long an entry lives is cn1.cache.<name>.ttl in seconds, then cn1.cache.ttl, then spring.cache.redis.time-to-live; unset, it lives until evicted.

Methods

public abstract String[] value() default {}The cache’s name; the first is used when several are given.
public abstract String[] cacheNames() default {}The same as value, as Spring spells it.
public abstract String key() default ""The key expression; see the class description.
public abstract String unless() default ""Accepted when it is #result == null, which is what happens anyway; any other expression fails the build.

Method details

value

public abstract String[] value() default {}
The cache’s name; the first is used when several are given.

cacheNames

public abstract String[] cacheNames() default {}
The same as value, as Spring spells it.

key

public abstract String key() default ""
The key expression; see the class description.

unless

public abstract String unless() default ""
Accepted when it is #result == null, which is what happens anyway; any other expression fails the build.