Skip to content

Commit 056831f

Browse files
authored
IGNITE-28475 Document CacheInterceptor interaction with keepBinary cache wrapper (#13002)
1 parent 7ca39e3 commit 056831f

3 files changed

Lines changed: 57 additions & 1 deletion

File tree

docs/_docs/code-snippets/java/src/main/java/org/apache/ignite/snippets/WorkingWithBinaryObjects.java

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,45 @@ public static void configuringBinaryObjects() {
142142

143143
}
144144

145+
//tag::keepBinaryWithCacheInterceptor[]
146+
public static void cacheWithInterceptorExample() {
147+
try (Ignite ignite = Ignition.start()) {
148+
CacheConfiguration specConfig = new CacheConfiguration("personSpecCache");
149+
ccfg.setInterceptor(new CustomInterceptor(false));
150+
IgniteCache<Integer, Person> cache = ignite.createCache(ccfg);
151+
cache.put(1, new Person(1, "FirstPerson"));
152+
153+
CacheConfiguration boConfig = new CacheConfiguration("boSpecCache");
154+
ccfg.setInterceptor(new CustomInterceptor(true));
155+
IgniteCache<Integer, Person> cache = ignite.createCache(ccfg);
156+
cache = cache.withKeepBinary();
157+
cache.put(1, new Person(1, "FirstPerson"));
158+
}
159+
}
160+
161+
private static class CustomInterceptor implements CacheInterceptor<Object, Object> {
162+
boolean keepBinary;
163+
164+
CustomInterceptor(boolean keepBinary) {
165+
this.keepBinary = keepBinary;
166+
}
167+
168+
@Nullable @Override public Object onBeforePut(Cache.Entry<Object, Object> entry, Object newVal) {
169+
assert keepBinary == newVal instanceof BinaryObject;
170+
// do smth.
171+
}
172+
173+
@Nullable @Override public IgniteBiTuple<Boolean, Object> onBeforeRemove(Cache.Entry<Object, Object> entry) {
174+
Object val = entry.getValue();
175+
176+
if (val != null) {
177+
assert keepBinary == entry.getValue() instanceof BinaryObject;
178+
}
179+
// do smth.
180+
}
181+
}
182+
//end::keepBinaryWithCacheInterceptor[]
183+
145184
private static class MyBinaryNameMapper implements BinaryNameMapper {
146185

147186
@Override

docs/_docs/key-value-api/binary-objects.adoc

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,21 @@ The following classes are never converted (e.g., the `toBinary(Object)` method r
7171
* `Enums` and array of enums
7272
* Maps, collections and arrays of objects (but the objects inside them are reconverted if they are binary)
7373

74+
`CacheInterceptor` also take into account cache `keepBinary` mode and process a value appropriately.
75+
76+
[tabs]
77+
--
78+
tab:Java[]
79+
[source,java]
80+
----
81+
include::{javaCodeDir}/WorkingWithBinaryObjects.java[tag=keepBinaryWithCacheInterceptor,indent=0]
82+
----
83+
84+
tab:C#/.NET[unsupported]
85+
86+
tab:C++[unsupported]
87+
--
88+
7489
tab:C#/.NET[]
7590
[source,csharp]
7691
----
@@ -177,7 +192,6 @@ tab:C#/.NET[unsupported]
177192
tab:C++[unsupported]
178193
--
179194

180-
181195
== Recommendations on Binary Objects Tuning
182196

183197
Ignite keeps a _schema_ for every Binary Object of a given type, which specifies the fields present in the object as well as their order and types.

modules/core/src/main/java/org/apache/ignite/cache/CacheInterceptor.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,9 @@
3333
* Cache interceptor is configured via {@link CacheConfiguration#getInterceptor()}
3434
* configuration property.
3535
* <p>
36+
* The type of incoming values depends on cache operation context, that is, the {@link IgniteCache#withKeepBinary()}
37+
* is taken into account.
38+
* <p>
3639
* Any grid resource from {@code org.apache.ignite.resources} package can be injected
3740
* into implementation of this interface.
3841
*/

0 commit comments

Comments
 (0)