java - Data retrieval optimization using AOP in a REST service -


i'm implementing rest service using spring mvc (spring boot) , i'm creating aspects handle cross functionalities of service.

an example service method this:

public void dosomethingwithuser(int userid){     // retrieve user db , something... } 

and in aspect class method this:

@around("execution(* com.test.myrestsvc.services.myservice.dosomethingwithuser(..))") public void arounddosomething(proceedingjoinpoint pjp) throws throwable {     // retrieve user (the same retrieved in method) , else... } 

as can see, have 2 methods doing different things same user object, have execute same query 2 times if user retrieved in main method.

note methods in service layer have several aspects triggered single method invocation, multiply user retrieval several times.

so i'm wondering: there way share objects @ least among aspects in rest (stateless) application? can suggest different approach minimize data access in these situations?

you can try use spring level caching, here simple tutorial, careful , pay additional attention on cache eviction policies.

if you're using spring data jpa hibernate or eclipselink, can try enable second level caching in jpa implementation provider: example


Comments

Popular posts from this blog

matlab - error with cyclic autocorrelation function -

django - (fields.E300) Field defines a relation with model 'AbstractEmailUser' which is either not installed, or is abstract -

c# - What is a good .Net RefEdit control to use with ExcelDna? -