From 84d056b64884a5e5ce0906ce8519fe960b5ce703 Mon Sep 17 00:00:00 2001 From: Mirco Nasuti <mirco.nasuti@chuv.ch> Date: Fri, 11 Nov 2016 13:40:30 +0100 Subject: [PATCH] workaround to evict cache session by session on Models and Articles --- .../java/eu/hbp/mip/controllers/ArticlesApi.java | 15 +++++++++++++-- .../java/eu/hbp/mip/controllers/ModelsApi.java | 15 +++++++++++++-- 2 files changed, 26 insertions(+), 4 deletions(-) diff --git a/src/main/java/eu/hbp/mip/controllers/ArticlesApi.java b/src/main/java/eu/hbp/mip/controllers/ArticlesApi.java index 71c3f1460..650116b1f 100644 --- a/src/main/java/eu/hbp/mip/controllers/ArticlesApi.java +++ b/src/main/java/eu/hbp/mip/controllers/ArticlesApi.java @@ -16,6 +16,7 @@ import org.springframework.beans.factory.annotation.Autowired; import org.springframework.cache.annotation.CacheEvict; import org.springframework.cache.annotation.CachePut; import org.springframework.cache.annotation.Cacheable; +import org.springframework.cache.annotation.Caching; import org.springframework.context.annotation.Scope; import org.springframework.http.HttpStatus; import org.springframework.http.ResponseEntity; @@ -82,7 +83,12 @@ public class ArticlesApi { @ApiOperation(value = "Create an article") @ApiResponses(value = { @ApiResponse(code = 201, message = "Article created") }) @CachePut(value = "Article", key = "#article.getSlug() + #root.target") - @CacheEvict(value = "Articles", allEntries = true) + @Caching(evict = { + @CacheEvict(value = "Articles", key = "'false' + 'draft' + #root.target"), + @CacheEvict(value = "Articles", key = "'false' + 'published' + #root.target"), + @CacheEvict(value = "Articles", key = "'true' + 'draft' + #root.target"), + @CacheEvict(value = "Articles", key = "'true' + 'published' + #root.target") + }) @RequestMapping(method = RequestMethod.POST) public ResponseEntity<Void> addAnArticle( @RequestBody @ApiParam(value = "Article to create", required = true) @Valid Article article @@ -173,7 +179,12 @@ public class ArticlesApi { @ApiOperation(value = "Update an article") @ApiResponses(value = { @ApiResponse(code = 204, message = "Article updated") }) @CachePut(value = "Article", key = "#slug + #root.target") - @CacheEvict(value = "Articles",allEntries = true) + @Caching(evict = { + @CacheEvict(value = "Articles", key = "'false' + 'draft' + #root.target"), + @CacheEvict(value = "Articles", key = "'false' + 'published' + #root.target"), + @CacheEvict(value = "Articles", key = "'true' + 'draft' + #root.target"), + @CacheEvict(value = "Articles", key = "'true' + 'published' + #root.target") + }) @RequestMapping(value = "/{slug}", method = RequestMethod.PUT) public ResponseEntity<Void> updateAnArticle( @ApiParam(value = "slug", required = true) @PathVariable("slug") String slug, diff --git a/src/main/java/eu/hbp/mip/controllers/ModelsApi.java b/src/main/java/eu/hbp/mip/controllers/ModelsApi.java index 2df27612c..1cce4e252 100644 --- a/src/main/java/eu/hbp/mip/controllers/ModelsApi.java +++ b/src/main/java/eu/hbp/mip/controllers/ModelsApi.java @@ -20,6 +20,7 @@ import org.springframework.beans.factory.annotation.Qualifier; import org.springframework.cache.annotation.CacheEvict; import org.springframework.cache.annotation.CachePut; import org.springframework.cache.annotation.Cacheable; +import org.springframework.cache.annotation.Caching; import org.springframework.context.annotation.Scope; import org.springframework.http.HttpStatus; import org.springframework.http.ResponseEntity; @@ -108,7 +109,12 @@ public class ModelsApi { @ApiOperation(value = "Create a model", response = Model.class) @ApiResponses(value = { @ApiResponse(code = 201, message = "Model created") }) @CachePut(value = "Model", key = "#model.getSlug() + #root.target") - @CacheEvict(value = "Models", allEntries = true) + @Caching(evict = { + @CacheEvict(value = "Models", key = "'false' + 'false' + #root.target"), + @CacheEvict(value = "Models", key = "'false' + 'true' + #root.target"), + @CacheEvict(value = "Models", key = "'true' + 'false' + #root.target"), + @CacheEvict(value = "Models", key = "'true' + 'true' + #root.target") + }) @RequestMapping(method = RequestMethod.POST) public ResponseEntity<Model> addAModel( @RequestBody @ApiParam(value = "Model to create", required = true) Model model @@ -228,7 +234,12 @@ public class ModelsApi { @ApiOperation(value = "Update a model", response = Void.class) @ApiResponses(value = { @ApiResponse(code = 204, message = "Model updated") }) @CachePut(value = "model", key = "#slug + #root.target") - @CacheEvict(value = "Models", allEntries = true) + @Caching(evict = { + @CacheEvict(value = "Models", key = "'false' + 'false' + #root.target"), + @CacheEvict(value = "Models", key = "'false' + 'true' + #root.target"), + @CacheEvict(value = "Models", key = "'true' + 'false' + #root.target"), + @CacheEvict(value = "Models", key = "'true' + 'true' + #root.target") + }) @RequestMapping(value = "/{slug}", method = RequestMethod.PUT) public ResponseEntity<Void> updateAModel( @ApiParam(value = "slug", required = true) @PathVariable("slug") String slug, -- GitLab