1, define a slice, useafterreturningnotifications, modifications, deletions, additions, etc. to update the cache after success
A, modify the database data first, modify the success and then sync to the cache,
b, delete the database data first, delete the corresponding data in the cache and then clean up
C, insert the database first, insert the success, and then sync into the cache
Com.aspect.demo;com.model.company;com.model.exceptioncompany;com. Cache.rediscache;org.aspectj.lang.joinpoint;org.aspectj.lang.annotation.*;org.slf4j.logger;o Rg.slf4j.LoggerFactory;; Java.util.List; The receivecachemanager { //cache management class is used to get the unit information data in the cache rediscache ; setrediscache (Rediscache rediscache) { .= redisCache; } Logger = Loggerfactory. (Receivecachemanager.); () insertservice () { } () updateservice () { } () DeleteService () { } () Insertcompany (Joinpoint joinpoint) { {
//Get method Parameters Object[] args = Joinpoint.getargs (); (Args != && args.> && args[].getclass () == Company.) { Company company = (company) args[]; (. Exists ()) { object object = .get (); ( object == ) {}{ List< exceptioncompany> list = (list<exceptioncompany>) object; exceptioncompany exceptioncompany = exceptioncompany ( ); exceptioncompany.setbusinesslicense ( Company.getbusinesslicense ()); &nbsP; exceptioncompany.setcompanyname (company.getCompanyName ()); exceptioncompany.setcompanyaddress ( Company.getcompanyaddress ()); Exceptioncompany.setlinkman (Company.getlinkman ()); exceptioncompany.setlinktel (Company.getlinktel ()); exceptioncompany.setorganiZationcode (Company.getorganizationcode ()); Exceptioncompany.settaxregistration (Company.gettaxregistration ()); list.add (Exceptioncompany); .set (, list); } } } .info (+ (Joinpoint.gettarget (). GetClass (). GetName () + + joinpoint.getsignature (). GetName () + ); } (exception e) { .error (, e.getMessage ()); } } (pointcut=) updatecompany (joinpoint Joinpoint) { {
Get method Parameter object[] args = joinpoint.getargs (); (args ! = && args.> && args[].getclass () == company.) { company company = (company) args[]; (. exists ()) { object object = .get (); ( object == ) {}{ list<exceptioncompany> list = (list<exceptioncompany>) object; (I= ;i<list.size (); i++) { (List.get (i). GetId (). Equals (Company.getid ())) { list.get (i). Setbusinesslicense (Company.getbusinesslicense ()); list.get (i). SetCompanyName (Company.getcompanyname()); list.get (i). Setcompanyaddress (Company.getcompanyaddress ()); list.get (i). Setlinkman (Company.getlinkman ()); list.get (i). Setlinktel (Company.getlinktel ()); list.get (i). SetOrganizationCode ( Company.getorganizationcode ()); list.get (i). Settaxregistration ( Company.gettaxregistration ()); ; } } .set (, list); } } } .info (+ (Joinpoint.gettarget (). GetClass (). GetName () + + joinpoint.getsignature (). GetName () + ); } (exception e) { .error (, e.getmessage ()); } } () deletecompany (joinpoint joinpoint) { {
Get method Parameter object[] args = joinpoint.getargs (); (args ! = && args.> && args[].getclass () == company.) { company company = (company) args[]; (. exists ()) { object object = .get (); ( object == ) { }{ list<exceptioncompany> list = (List<ExceptionCompany>) object; (I= ;i<list.size (); i++) { (List.get (i). GetId (). Equals (Company.getid ())) { list.remove (List.get (i)); ; } } .set (, list); } } } } (exception e) { } }}2, In the Application-*.xml file, addEnter the following configuration: <!--use <aop:aspectj-autoproxy/> to turn on annotation style @aspectj support--> <!--SPRING&NBSP;AOP Configuration Use Cglib dynamic Agent technology to weave into enhanced-->&NBSP;&NBSP;&NBSP;&NBSP;<AOP: aspectj-autoproxy/> <!--Facets--> <bean id= " Receivecache " class=" Com.aspect.demo.ReceiveCacheManager "/>
Springaop implementing Redis Cache and MySQL database synchronization