com.jarvis.cache.serializer.kryo.CacheWrapperSerializer Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of autoload-cache-serializer-kryo Show documentation
Show all versions of autoload-cache-serializer-kryo Show documentation
The serializer module of autoload-cache project
package com.jarvis.cache.serializer.kryo;
import com.esotericsoftware.kryo.Kryo;
import com.esotericsoftware.kryo.Serializer;
import com.esotericsoftware.kryo.io.Input;
import com.esotericsoftware.kryo.io.Output;
import com.jarvis.cache.to.CacheWrapper;
/**
* autoload-cache CacheWrapper Serializer
*
* @author stevie.wong
*/
public class CacheWrapperSerializer extends Serializer {
@Override
@SuppressWarnings("unchecked")
public void write(Kryo kryo, Output output, CacheWrapper object) {
output.writeInt(object.getExpire(), true);
output.writeLong(object.getLastLoadTime(), true);
kryo.writeClassAndObject(output, object.getCacheObject());
}
@Override
@SuppressWarnings("unchecked")
public CacheWrapper read(Kryo kryo, Input input, Class type) {
int expire = input.readInt(true);
long lastLoadTime = input.readLong(true);
Object o = kryo.readClassAndObject(input);
CacheWrapper cacheWrapper = new CacheWrapper();
cacheWrapper.setCacheObject(o);
cacheWrapper.setExpire(expire);
cacheWrapper.setLastLoadTime(lastLoadTime);
return cacheWrapper;
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy