You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This chapter describes additional support for caching and `@Cacheable`.
5
+
6
+
[[caching.usage]]
7
+
== Configuration & Usage
8
+
9
+
Technically, caching is not part of spring-data, but is implemented directly in the spring core. Most database implementations in the spring-data package can't support `@Cacheable`, because it is not possible to store arbitrary data.
10
+
11
+
Couchbase supports both binary and JSON data, so you can get both out of the same database.
12
+
13
+
To make it work, you need to add the `@EnableCaching` annotation and configure the `cacheManager` bean:
14
+
15
+
.`AbstractCouchbaseConfiguration` for Caching
16
+
====
17
+
[source,java]
18
+
----
19
+
20
+
@Configuration
21
+
@EnableCaching
22
+
public class Config extends AbstractCouchbaseConfiguration {
23
+
// general methods
24
+
25
+
@Bean
26
+
public CouchbaseCacheManager cacheManager(CouchbaseTemplate couchbaseTemplate) throws Exception {
The `persistent` identifier can then be used on the `@Cacheable` annotation to identify the cache manager to use (you can have more than one configured).
36
+
37
+
Once it is set up, you can annotate every method with the `@Cacheable` annotation to transparently cache it in your couchbase bucket. You can also customize how the key is generated.
If you run the method multiple times, you'll see a set operation happening first, followed by multiple get operations and no sleep time (which fakes the expensive execution). You can store whatever you want, if it is JSON of course you can access it through views and look at it in the Web UI.
56
+
57
+
Note that to use cache.clear() or catch.invalidate(), the bucket must have a primary key.
0 commit comments