i have map stores simple pojos, key id field of pojo. spring's @cacheput annotation, expected this:
jobmodel jm = new jobmodel(); cachemap.put(jm.getid(), jm);
still, inserts null values cache every time. if disallow null values when configure cache, en exception saying null being inserted.
code:
@springbootapplication @enablescheduling @enableautoconfiguration @enablecaching public class application { public static void main(string[] args) { applicationcontext = springapplication.run(application.class, args); }
...
private guavacache jobcache() { return new guavacache(cachenames.cache_job, cachebuilder.newbuilder() .maximumsize(999999) .build(), false);// or true, still null values } @bean(name = "cachemanager") public cachemanager cachemanager() { simplecachemanager simplecachemanager = new simplecachemanager(); simplecachemanager.setcaches(arrays.aslist( jobcache(),.... )); return simplecachemanager; }
and dao class, implementing interface, annotations declared in dao's (the class implements interface, not in interface itself)
@cacheput(value = cachenames.cache_job,key = "jm.id") @transactional @override public void insert(jobmodel jm) {...}
i tried jm.id
, jm.getid()
, #a0.getid()
. still, everytime , exception com.google.common.base.preconditions.checknotnull()
(or simple null insert). placed breakpoint there , can see key expected (a guid, string), value null.
per spring docs @ http://docs.spring.io/spring/docs/current/javadoc-api/org/springframework/cache/annotation/cacheput.html
it causes method invoked , result stored in associated cache.
your insert method needs return value want cached.
could simple as:
@cacheput(value = cachenames.cache_job,key = "jm.id") @transactional @override public jobmodel insert(jobmodel jm) { return jm; }
though doesn't feel best way design interaction. may want @ moving annotation whatever method constructing jobmodel passed insert method or if jobmodel being read database, method saves jobmodel database may place well.
Comments
Post a Comment