Custom KeyGenerator

This commit adds an extra parameter to the base @Cache method
annotations: keyGenerator. This parameter holds the name of the
KeyGenerator bean to use to compute the key for that specific
caching endpoint.

This gives therefore a third way to customize the key. These are:
1. Default KeyGenerator (global for all endpoints)
2. The 'key' attribute of the annotation, giving the SpEL expression to use
3. The 'keyGenerator' attribute of the annotation

The annotation attributes are therefore exclusive. Trying to specify
them both will result in an IllegalStateException.

The KeyGenerator to use for a given operation is cached on startup
so that multiple calls to it does not resolve the instance to use over and
over again.

Issue: SPR-10629
This commit is contained in:
Stephane Nicoll
2014-01-10 16:24:51 +01:00
parent 906321dcdd
commit 81c208098f
25 changed files with 407 additions and 38 deletions

View File

@@ -176,9 +176,15 @@
<xsd:attribute name="key" type="xsd:string" use="optional">
<xsd:annotation>
<xsd:documentation><![CDATA[
The SpEL expression used for computing the cache key.]]></xsd:documentation>
The SpEL expression used for computing the cache key, mutually exclusive with the key-generator parameter.]]></xsd:documentation>
</xsd:annotation>
</xsd:attribute>
<xsd:attribute name="key-generator" type="xsd:string" use="optional">
<xsd:annotation>
<xsd:documentation><![CDATA[
The name of the KeyGenerator bean responsible to compute the key, mutually exclusive with the key parameter.]]></xsd:documentation>
</xsd:annotation>
</xsd:attribute>
<xsd:attribute name="condition" type="xsd:string" use="optional">
<xsd:annotation>
<xsd:documentation><![CDATA[