@@ -6615,7 +6615,6 @@ has it applied automatically:
6615
6615
protected void executeInternal(JobExecutionContext ctx) throws JobExecutionException {
6616
6616
// do the actual work
6617
6617
}
6618
-
6619
6618
}
6620
6619
----
6621
6620
@@ -6740,11 +6739,17 @@ seconds and one running every morning at 6 AM. To finalize everything, we need t
6740
6739
</bean>
6741
6740
----
6742
6741
6743
- More properties are available for the `SchedulerFactoryBean`, such as the calendars
6744
- used by the job details, properties to customize Quartz with, and others . See the
6745
- {api-spring-framework}/scheduling/quartz/SchedulerFactoryBean.html[`SchedulerFactoryBean`]
6742
+ More properties are available for the `SchedulerFactoryBean`, such as the calendars used by the
6743
+ job details, properties to customize Quartz with, and a Spring-provided JDBC DataSource . See
6744
+ the {api-spring-framework}/scheduling/quartz/SchedulerFactoryBean.html[`SchedulerFactoryBean`]
6746
6745
javadoc for more information.
6747
6746
6747
+ NOTE: `SchedulerFactoryBean` also recognizes a `quartz.properties` file in the classpath,
6748
+ based on Quartz property keys, as with regular Quartz configuration. Please note that many
6749
+ `SchedulerFactoryBean` settings interact with common Quartz settings in the properties file;
6750
+ it is therefore not recommended to specify values at both levels. For example, do not set
6751
+ an "org.quartz.jobStore.class" property if you mean to rely on a Spring-provided DataSource.
6752
+
6748
6753
6749
6754
6750
6755
@@ -6756,8 +6761,8 @@ an existing Spring application. Similar to the <<data-access.adoc#transaction, t
6756
6761
support, the caching abstraction allows consistent use of various caching solutions with
6757
6762
minimal impact on the code.
6758
6763
6759
- As from Spring 4.1, the cache abstraction has been significantly extended with the
6760
- support of <<cache-jsr-107,JSR-107 annotations>> and more customization options.
6764
+ In Spring Framework 4.1, the cache abstraction was significantly extended with support
6765
+ for <<cache-jsr-107,JSR-107 annotations>> and more customization options.
6761
6766
6762
6767
6763
6768
@@ -6815,15 +6820,16 @@ compliant caches (such as Ehcache 3.x). See <<cache-plug>> for more information
6815
6820
plugging in other cache stores and providers.
6816
6821
6817
6822
IMPORTANT: The caching abstraction has no special handling for multi-threaded and
6818
- multi-process environments, as such features are handled by the cache implementation. .
6823
+ multi-process environments, as such features are handled by the cache implementation.
6819
6824
6820
6825
If you have a multi-process environment (that is, an application deployed on several nodes),
6821
6826
you need to configure your cache provider accordingly. Depending on your use cases, a copy
6822
6827
of the same data on several nodes can be enough. However, if you change the data during
6823
6828
the course of the application, you may need to enable other propagation mechanisms.
6824
6829
6825
- Caching a particular item is a direct equivalent of the typical get-if-not-found-then-
6826
- proceed-and-put-eventually code blocks found with programmatic cache interaction.
6830
+ Caching a particular item is a direct equivalent of the typical
6831
+ get-if-not-found-then-proceed-and-put-eventually code blocks
6832
+ found with programmatic cache interaction.
6827
6833
No locks are applied, and several threads may try to load the same item concurrently.
6828
6834
The same applies to eviction. If several threads are trying to update or evict data
6829
6835
concurrently, you may use stale data. Certain cache providers offer advanced features
@@ -6875,7 +6881,7 @@ method -- if at least one cache is hit, the associated value is returned.
6875
6881
NOTE: All the other caches that do not contain the value are also updated, even though
6876
6882
the cached method was not actually invoked.
6877
6883
6878
- The following example uses `@Cacheable` on the `findBook` method:
6884
+ The following example uses `@Cacheable` on the `findBook` method with multiple caches :
6879
6885
6880
6886
[source,java,indent=0]
6881
6887
[subs="verbatim,quotes"]
@@ -7028,7 +7034,7 @@ regardless of the content of the annotation.
7028
7034
7029
7035
Similarly to `key` and `keyGenerator`, the `cacheManager` and `cacheResolver`
7030
7036
parameters are mutually exclusive, and an operation specifying both
7031
- results in an exception. as a custom `CacheManager` is ignored by the
7037
+ results in an exception, as a custom `CacheManager` is ignored by the
7032
7038
`CacheResolver` implementation. This is probably not what you expect.
7033
7039
====
7034
7040
@@ -7053,7 +7059,6 @@ is updated in the cache. The following example shows how to use the `sync` attri
7053
7059
----
7054
7060
<1> Using the `sync` attribute.
7055
7061
7056
-
7057
7062
NOTE: This is an optional feature, and your favorite cache library may not support it.
7058
7063
All `CacheManager` implementations provided by the core framework support it. See the
7059
7064
documentation of your cache provider for more details.
@@ -7092,9 +7097,11 @@ want to cache paperback books, as the following example does:
7092
7097
<1> Using the `unless` attribute to block hardbacks.
7093
7098
7094
7099
7095
- The cache abstraction supports `java.util.Optional`, using its content as the cached value
7096
- only if it is present. `#result` always refers to the business entity and never a
7097
- supported wrapper, so the previous example can be rewritten as follows:
7100
+ The cache abstraction supports `java.util.Optional` return types. If an `Optional` value
7101
+ is _present_, it will be stored in the associated cache. If an `Optional` value is not
7102
+ present, `null` will be stored in the associated cache. `#result` always refers to the
7103
+ business entity and never a supported wrapper, so the previous example can be rewritten
7104
+ as follows:
7098
7105
7099
7106
[source,java,indent=0]
7100
7107
[subs="verbatim,quotes"]
@@ -7103,8 +7110,8 @@ supported wrapper, so the previous example can be rewritten as follows:
7103
7110
public Optional<Book> findBook(String name)
7104
7111
----
7105
7112
7106
- Note that `result` still refers to `Book` and not `Optional`. As it might be `null`, we
7107
- should use the safe navigation operator.
7113
+ Note that `# result` still refers to `Book` and not `Optional<Book> `. Since it might be
7114
+ `null`, we use SpEL's <<core.adoc#expressions-operator- safe-navigation, safe navigation operator>> .
7108
7115
7109
7116
[[cache-spel-context]]
7110
7117
===== Available Caching SpEL Evaluation Context
@@ -7214,7 +7221,6 @@ all entries from the `books` cache:
7214
7221
----
7215
7222
<1> Using the `allEntries` attribute to evict all entries from the cache.
7216
7223
7217
-
7218
7224
This option comes in handy when an entire cache region needs to be cleared out.
7219
7225
Rather than evicting each entry (which would take a long time, since it is inefficient),
7220
7226
all the entries are removed in one operation, as the preceding example shows.
@@ -7275,7 +7281,6 @@ comes into play. The following examples uses `@CacheConfig` to set the name of t
7275
7281
----
7276
7282
<1> Using `@CacheConfig` to set the name of the cache.
7277
7283
7278
-
7279
7284
`@CacheConfig` is a class-level annotation that allows sharing the cache names,
7280
7285
the custom `KeyGenerator`, the custom `CacheManager`, and the custom `CacheResolver`.
7281
7286
Placing this annotation on the class does not turn on any caching operation.
@@ -7418,13 +7423,11 @@ if you need to annotate non-public methods, as it changes the bytecode itself.
7418
7423
****
7419
7424
7420
7425
TIP: Spring recommends that you only annotate concrete classes (and methods of concrete
7421
- classes) with the `@Cache{asterisk}` annotation, as opposed to annotating interfaces.
7422
- You certainly can place the `@Cache{asterisk}` annotation on an interface (or an interface
7423
- method), but this works only as you would expect it to if you use interface-based proxies.
7424
- The fact that Java annotations are not inherited from interfaces means that, if you use
7425
- class-based proxies (`proxy-target-class="true"`) or the weaving-based aspect
7426
- (`mode="aspectj"`), the caching settings are not recognized by the proxying and weaving
7427
- infrastructure, and the object is not wrapped in a caching proxy.
7426
+ classes) with the `@Cache{asterisk}` annotations, as opposed to annotating interfaces.
7427
+ You certainly can place an `@Cache{asterisk}` annotation on an interface (or an interface
7428
+ method), but this works only if you use the proxy mode (`mode="proxy"`). If you use the
7429
+ weaving-based aspect (`mode="aspectj"`), the caching settings are not recognized on
7430
+ interface-level declarations by the weaving infrastructure.
7428
7431
7429
7432
NOTE: In proxy mode (the default), only external method calls coming in through the
7430
7433
proxy are intercepted. This means that self-invocation (in effect, a method within the
@@ -7499,7 +7502,7 @@ up its declaration at runtime and understands its meaning. Note that, as mention
7499
7502
=== JCache (JSR-107) Annotations
7500
7503
7501
7504
Since version 4.1, Spring's caching abstraction fully supports the JCache standard
7502
- annotations: `@CacheResult`, `@CachePut`, `@CacheRemove`, and `@CacheRemoveAll`
7505
+ (JSR-107) annotations: `@CacheResult`, `@CachePut`, `@CacheRemove`, and `@CacheRemoveAll`
7503
7506
as well as the `@CacheDefaults`, `@CacheKey`, and `@CacheValue` companions.
7504
7507
You can use these annotations even without migrating your cache store to JSR-107.
7505
7508
The internal implementation uses Spring's caching abstraction and provides default
@@ -7513,8 +7516,8 @@ you can switch to these standard annotations without changing your cache storage
7513
7516
==== Feature Summary
7514
7517
7515
7518
For those who are familiar with Spring's caching annotations, the following table
7516
- describes the main differences between the Spring annotations and the JSR-107
7517
- counterpart :
7519
+ describes the main differences between the Spring annotations and their JSR-107
7520
+ counterparts :
7518
7521
7519
7522
.Spring vs. JSR-107 caching annotations
7520
7523
[cols="1,1,3"]
@@ -7565,7 +7568,6 @@ to customize the factory for each cache operation, as the following example show
7565
7568
----
7566
7569
<1> Customizing the factory for this operation.
7567
7570
7568
-
7569
7571
NOTE: For all referenced classes, Spring tries to locate a bean with the given type.
7570
7572
If more than one match exists, a new instance is created and can use the regular
7571
7573
bean lifecycle callbacks, such as dependency injection.
@@ -7609,16 +7611,15 @@ invoking the method again:
7609
7611
7610
7612
==== Enabling JSR-107 Support
7611
7613
7612
- You need do nothing specific to enable the JSR-107 support alongside Spring's
7613
- declarative annotation support. Both `@EnableCaching` and the
7614
- `cache:annotation-driven` element automatically enable the JCache support
7615
- if both the JSR-107 API and the `spring-context-support` module are present
7616
- in the classpath.
7614
+ You do not need to do anything specific to enable the JSR-107 support alongside Spring's
7615
+ declarative annotation support. Both `@EnableCaching` and the `cache:annotation-driven`
7616
+ XML element automatically enable the JCache support if both the JSR-107 API and the
7617
+ `spring-context-support` module are present in the classpath.
7617
7618
7618
- NOTE: Depending on your use case, the choice is basically yours. You can even
7619
- mix and match services by using the JSR-107 API on some and using Spring's own
7620
- annotations on others. However, if these services impact the same caches,
7621
- you should use a consistent and identical key generation implementation.
7619
+ NOTE: Depending on your use case, the choice is basically yours. You can even mix and
7620
+ match services by using the JSR-107 API on some and using Spring's own annotations on
7621
+ others. However, if these services impact the same caches, you should use a consistent
7622
+ and identical key generation implementation.
7622
7623
7623
7624
7624
7625
@@ -7848,15 +7849,13 @@ invoked every time.
7848
7849
=== Plugging-in Different Back-end Caches
7849
7850
7850
7851
Clearly, there are plenty of caching products out there that you can use as a backing
7851
- store. To plug them in, you need to provide a `CacheManager` and a `Cache` implementation,
7852
- since, unfortunately, there is no available standard that we can use instead.
7853
- This may sound harder than it is, since, in practice, the classes tend to be simple
7854
- https://en.wikipedia.org/wiki/Adapter_pattern[adapters] that map the caching abstraction
7855
- framework on top of the storage API, as the `ehcache` classes do. Most `CacheManager`
7856
- classes can use the classes in the `org.springframework.cache.support` package
7857
- (such as `AbstractCacheManager` which takes care of the boiler-plate code,
7858
- leaving only the actual mapping to be completed). We hope that, in time, the libraries
7859
- that provide integration with Spring can fill in this small configuration gap.
7852
+ store. For those that do not support JSR-107 you need to provide a `CacheManager` and a
7853
+ `Cache` implementation. This may sound harder than it is, since, in practice, the classes
7854
+ tend to be simple https://en.wikipedia.org/wiki/Adapter_pattern[adapters] that map the
7855
+ caching abstraction framework on top of the storage API, as the `ehcache` classes do.
7856
+ Most `CacheManager` classes can use the classes in the
7857
+ `org.springframework.cache.support` package (such as `AbstractCacheManager` which takes
7858
+ care of the boiler-plate code, leaving only the actual mapping to be completed).
7860
7859
7861
7860
7862
7861
0 commit comments