google-code-export / ehcache-spring-annotations

Automatically exported from code.google.com/p/ehcache-spring-annotations
0 stars 0 forks source link

Allow using an instance variable in combination to arguments as key #69

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
Assume we have a DAO

   public class DAO {
      private String collection;

      public DAO(Collection collection) {
          this.collection = collection;
      }

      @Cacheable(key = @CombinedKey(
           @InstanceKey("collection"),
           @ArgumentKey("key")
      ))
      public Entity find(String key) {
           return // from table where key=? and collection=?
      }

   }

So what I wanted to illustrate with the example is that the cache key should be 
the combination of the "String key" argument and instance variable "String 
collection". 

This would be really useful when several threads exist which each holds an DAO 
instance, but initialized with different "collection" settings, thereby 
logically separating them both in the database and the cache. 

Original issue reported on code.google.com by johan.sj...@gmail.com on 10 Mar 2011 at 2:35

GoogleCodeExporter commented 9 years ago
[deleted comment]
GoogleCodeExporter commented 9 years ago
This is technically possible using already with the SpELCacheKeyGenerator, e.g, 
with the expression "#invocation.getThis().getCollection()". 

Original comment by johan.sj...@gmail.com on 13 Mar 2011 at 7:50

GoogleCodeExporter commented 9 years ago
I think the SpEL generator is your best bet here. To get this working without 
SpEL would require doing reflection at runtime.

Original comment by eric.dalquist on 19 Apr 2011 at 10:43