dinesh94 / simple-spring-memcached

Automatically exported from code.google.com/p/simple-spring-memcached
MIT License
0 stars 0 forks source link

Do not support the no-argument method #9

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
Code:
----
public interface RoleDao {
    List getRoles();
}

@Repository
public class RoleDaoImpl implements RoleDao {

    @Override
    @ReadThroughMultiCache(namespace = "role/list", expiration = 60)
    public List<Role> getRoles() {
        return sqlMapClientTemplate.queryForList("getRoles");
    }
}

Result:
----
WARN 2012-09-21 15:04:07,374 com.google.code.ssm.aop.CacheAdvice: Caching on 
execution(RoleDao.getRoles()) aborted due to an error.
java.security.InvalidParameterException: No KeyProvider annotation found method 
[getRoles]

Question:
----
Why must use the parameter as a key? Can I use other hash strategy?

Original issue reported on code.google.com by zhaob...@gmail.com on 21 Sep 2012 at 7:11

GoogleCodeExporter commented 9 years ago
Sorry! @ReadThroughAssignCache is ok.

Original comment by zhaob...@gmail.com on 21 Sep 2012 at 8:07

GoogleCodeExporter commented 9 years ago
Please close it.

Original comment by zhaob...@gmail.com on 21 Sep 2012 at 8:14

GoogleCodeExporter commented 9 years ago
If you don't want to use any of the method's parameters as a part of cache key 
then use 'assign' cache. In your case @ReadThroughAssignCache. It will store 
data under defined and constant (= assign) cache key.
Keeping list of objects under one key is not best solution when also separated 
object (Role) is stored. The drawback is higher memory consumption and complex 
update&invalidate process. Each time the object need to be updated all its 
copies in cache have to be updated otherwise cache become inconsistent. 
The solution to this problem that I use is to keep each object in cache only 
once and refer to it using object id. 
In you case each Role should be store under different cache key (using roleId) 
and instead of keeping list of all Roles store list of all Roles' ids. Using 
the ids you can fetch all Roles. 

Original comment by ragno...@gmail.com on 21 Sep 2012 at 8:37