import grails.plugin.springcache.CacheResolver class CustomCacheResolver implements CacheResolver { def authenticateService String resolveCacheName(String baseName) { def user = authenticateService.principal().domainClass user = User.get(user.id) def bancheIds = user.banche*.getId().sort().join("_") "${baseName}-banche-${bancheIds}" } }
and then wire authenticateService in resources.groovy:
customCacheResolver(CustomCacheResolver) { authenticateService = ref("authenticateService") }
now it can be referenced from SpringCache annotations:
@CacheFlush(caches = "categorieCache", cacheResolver = "customCacheResolver")
and every tenant (defined by banche collection identifiers) has its cache.
Note that I used Acegi plugin, which now is discontinued, but I think the same could be obtained with SpringSecurity plugin also. Just wire springSecurityService and resolve current logged user from it with getCurrentUser().
Nessun commento:
Posta un commento