Closed GoogleCodeExporter closed 9 years ago
Thanks for the patch!
Adding cache name or alias as a prefix to key can be useful to avoid keys'
collision. I haven't got time to review your patch but it seams that it will
always prefix keys. It will break backward compatibility with previous version
of SSM - different cache key will be generated for the same object by current a
new version of SSM. I think that key prefixing should be optional and by
default disabled to keep backward compatibility.
Original comment by ragno...@gmail.com
on 4 Oct 2013 at 6:00
You're right. cache name or alias are always prefix cache key.
So I made SSMKeyGenerator interface.
If you change SSMKeyGenerator, you can disable prefixing key.
But I made default SSMKeyGenerator to prefix cache name/alias.
Original comment by kwon3...@gmail.com
on 4 Oct 2013 at 6:12
Base on your patch I've implemented it in a slightly different way. A new class
PrefixedCacheImpl is used to wrap all requests and alter cache key before
invoking CacheImpl. By default PrefixedCacheImpl is not used.
To enable it:
<bean name="userCache" class="com.google.code.ssm.CacheFactory">
<property name="cacheName" value="userCache" />
.....
<property name="configuration">
<bean class="com.google.code.ssm.providers.CacheConfiguration">
........
<property name="useNameAsKeyPrefix" value="true" />
</bean>
</property>
<property name="cacheAliases">
<set>
<value>userAliasCache1</value>
<value>userAliasCache2</value>
</set>
</property>
</bean>
and if you want to make the cache available in Spring under aliases:
<bean name="cacheManager" class="com.google.code.ssm.spring.SSMCacheManager">
<property name="caches">
<set>
<bean class="com.google.code.ssm.spring.SSMCache">
<constructor-arg name="cache" index="0" ref="userCache" />
<constructor-arg name="expiration" index="1" value="300" />
<constructor-arg name="allowClear" index="2" value="false" />
<constructor-arg name="registerAliases" index="3" value="true" />
</bean>
</set>
</property>
</bean>
Using above configuration you can use: userCache, userAliasCache1,
userAliasCache2 as a value in @Cacheable and depends on which value is used
cache keys will be prefixed with: userCache#, userAliasCache1#, userAliasCache2#
Original comment by ragno...@gmail.com
on 5 Dec 2013 at 12:28
Code in trunk.
Original comment by ragno...@gmail.com
on 5 Dec 2013 at 12:31
Oh, does it mean "cache name prefix key" is available for both the spring cache
abstraction and the original Simple Spring Memcached?
What a nice patch! That is the thing I really wanted.
Thanks!
Original comment by kwon3...@gmail.com
on 8 Dec 2013 at 12:42
Yes, it does :).
You can configure the library to use cache name/alias as a prefix for key in
the original SSM and Spring Cache abstraction.
Original comment by ragno...@gmail.com
on 8 Dec 2013 at 6:42
Included in release 3.3.0. The release is available in central maven
repository.
Original comment by ragno...@gmail.com
on 17 Jan 2014 at 6:17
Thanks for the fix, exactly what I needed!
Original comment by reinhard...@gmail.com
on 24 Mar 2014 at 2:27
Original issue reported on code.google.com by
kwon3...@gmail.com
on 3 Oct 2013 at 1:41Attachments: