Skip to content
Snippets Groups Projects
Commit 84d056b6 authored by Mirco Nasuti's avatar Mirco Nasuti
Browse files

workaround to evict cache session by session on Models and Articles

parent 415b25d4
No related branches found
No related tags found
No related merge requests found
...@@ -16,6 +16,7 @@ import org.springframework.beans.factory.annotation.Autowired; ...@@ -16,6 +16,7 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.CacheEvict; import org.springframework.cache.annotation.CacheEvict;
import org.springframework.cache.annotation.CachePut; import org.springframework.cache.annotation.CachePut;
import org.springframework.cache.annotation.Cacheable; import org.springframework.cache.annotation.Cacheable;
import org.springframework.cache.annotation.Caching;
import org.springframework.context.annotation.Scope; import org.springframework.context.annotation.Scope;
import org.springframework.http.HttpStatus; import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity; import org.springframework.http.ResponseEntity;
...@@ -82,7 +83,12 @@ public class ArticlesApi { ...@@ -82,7 +83,12 @@ public class ArticlesApi {
@ApiOperation(value = "Create an article") @ApiOperation(value = "Create an article")
@ApiResponses(value = { @ApiResponse(code = 201, message = "Article created") }) @ApiResponses(value = { @ApiResponse(code = 201, message = "Article created") })
@CachePut(value = "Article", key = "#article.getSlug() + #root.target") @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) @RequestMapping(method = RequestMethod.POST)
public ResponseEntity<Void> addAnArticle( public ResponseEntity<Void> addAnArticle(
@RequestBody @ApiParam(value = "Article to create", required = true) @Valid Article article @RequestBody @ApiParam(value = "Article to create", required = true) @Valid Article article
...@@ -173,7 +179,12 @@ public class ArticlesApi { ...@@ -173,7 +179,12 @@ public class ArticlesApi {
@ApiOperation(value = "Update an article") @ApiOperation(value = "Update an article")
@ApiResponses(value = { @ApiResponse(code = 204, message = "Article updated") }) @ApiResponses(value = { @ApiResponse(code = 204, message = "Article updated") })
@CachePut(value = "Article", key = "#slug + #root.target") @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) @RequestMapping(value = "/{slug}", method = RequestMethod.PUT)
public ResponseEntity<Void> updateAnArticle( public ResponseEntity<Void> updateAnArticle(
@ApiParam(value = "slug", required = true) @PathVariable("slug") String slug, @ApiParam(value = "slug", required = true) @PathVariable("slug") String slug,
......
...@@ -20,6 +20,7 @@ import org.springframework.beans.factory.annotation.Qualifier; ...@@ -20,6 +20,7 @@ import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.cache.annotation.CacheEvict; import org.springframework.cache.annotation.CacheEvict;
import org.springframework.cache.annotation.CachePut; import org.springframework.cache.annotation.CachePut;
import org.springframework.cache.annotation.Cacheable; import org.springframework.cache.annotation.Cacheable;
import org.springframework.cache.annotation.Caching;
import org.springframework.context.annotation.Scope; import org.springframework.context.annotation.Scope;
import org.springframework.http.HttpStatus; import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity; import org.springframework.http.ResponseEntity;
...@@ -108,7 +109,12 @@ public class ModelsApi { ...@@ -108,7 +109,12 @@ public class ModelsApi {
@ApiOperation(value = "Create a model", response = Model.class) @ApiOperation(value = "Create a model", response = Model.class)
@ApiResponses(value = { @ApiResponse(code = 201, message = "Model created") }) @ApiResponses(value = { @ApiResponse(code = 201, message = "Model created") })
@CachePut(value = "Model", key = "#model.getSlug() + #root.target") @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) @RequestMapping(method = RequestMethod.POST)
public ResponseEntity<Model> addAModel( public ResponseEntity<Model> addAModel(
@RequestBody @ApiParam(value = "Model to create", required = true) Model model @RequestBody @ApiParam(value = "Model to create", required = true) Model model
...@@ -228,7 +234,12 @@ public class ModelsApi { ...@@ -228,7 +234,12 @@ public class ModelsApi {
@ApiOperation(value = "Update a model", response = Void.class) @ApiOperation(value = "Update a model", response = Void.class)
@ApiResponses(value = { @ApiResponse(code = 204, message = "Model updated") }) @ApiResponses(value = { @ApiResponse(code = 204, message = "Model updated") })
@CachePut(value = "model", key = "#slug + #root.target") @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) @RequestMapping(value = "/{slug}", method = RequestMethod.PUT)
public ResponseEntity<Void> updateAModel( public ResponseEntity<Void> updateAModel(
@ApiParam(value = "slug", required = true) @PathVariable("slug") String slug, @ApiParam(value = "slug", required = true) @PathVariable("slug") String slug,
......
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment