GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — AbstractCacheEngine now using KryoUtils (#120) · voidframework/voidframework@995ba86

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
  • voidframework-cache/src/main/java/dev/voidframework/cache/engine
    • AbstractCacheEngine.java
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎voidframework-cache/src/main/java/dev/voidframework/cache/engine/AbstractCacheEngine.java‎

Copy file name to clipboardExpand all lines: voidframework-cache/src/main/java/dev/voidframework/cache/engine/AbstractCacheEngine.java
+4-23Lines changed: 4 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,9 @@
11
package dev.voidframework.cache.engine;
22

3-
import com.esotericsoftware.kryo.Kryo;
4-
import com.esotericsoftware.kryo.io.ByteBufferOutputStream;
5-
import com.esotericsoftware.kryo.io.Input;
6-
import com.esotericsoftware.kryo.io.Output;
3+
import dev.voidframework.core.utils.KryoUtils;
74

8-
import java.util.ArrayList;
95
import java.util.Arrays;
10-
import java.util.HashMap;
11-
import java.util.HashSet;
126
import java.util.Objects;
13-
import java.util.Optional;
147

158
/**
169
* This abstract implementation provides the necessary tools for the
@@ -20,22 +13,12 @@
2013
*/
2114
public abstract class AbstractCacheEngine implements CacheEngine {
2215

23-
private final Kryo kryo;
24-
2516
/**
2617
* Build a new instance.
2718
*
2819
* @since 1.1.0
2920
*/
3021
protected AbstractCacheEngine() {
31-
32-
this.kryo = new Kryo();
33-
kryo.setRegistrationRequired(false);
34-
kryo.register(ArrayList.class);
35-
kryo.register(Class.class);
36-
kryo.register(HashMap.class);
37-
kryo.register(HashSet.class);
38-
kryo.register(Optional.class);
3922
}
4023

4124
/**
@@ -47,11 +30,10 @@ protected AbstractCacheEngine() {
4730
*/
4831
public CachedElement wrap(final Object obj) {
4932

50-
final Output output = new Output(new ByteBufferOutputStream());
5133
final Class<?> classType = obj != null ? obj.getClass() : Object.class;
34+
final byte[] serializedContent = KryoUtils.serializeWithoutException(obj);
5235

53-
this.kryo.writeObjectOrNull(output, obj, classType);
54-
return new CachedElement(classType, output.toBytes());
36+
return new CachedElement(classType, serializedContent);
5537
}
5638

5739
/**
@@ -67,8 +49,7 @@ public Object unwrap(final CachedElement cachedElement) {
6749
return null;
6850
}
6951

70-
final Input input = new Input(cachedElement.content);
71-
return this.kryo.readObjectOrNull(input, cachedElement.classType);
52+
return KryoUtils.deserializeWithoutException(cachedElement.content, cachedElement.classType);
7253
}
7354

7455
/**

0 commit comments

Comments
0 (0)
You are visitor 01402520 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.