club.pizzalord.shire.serializer.protostuff.SchemaManager Maven / Gradle / Ivy
package club.pizzalord.shire.serializer.protostuff;
import club.pizzalord.shire.sdk.cache.LRUCache;
import io.protostuff.Schema;
import io.protostuff.runtime.RuntimeSchema;
/**
* Protostuff schema manager
*
* @author Xpizza
* @since shire1.0
*/
public class SchemaManager {
/**
* schema cache
*/
private static LRUCache> SCHEMA_CACHE = new LRUCache<>(100);
/**
* Get a protostuff schema
*
* @param clazz Object class
* @param Object type
* @return Protostuff schema
*/
public static Schema getSchema(Class clazz) {
Schema schema = (Schema) SCHEMA_CACHE.get(clazz.getName());
if (schema != null) {
return schema;
}
schema = RuntimeSchema.getSchema(clazz);
SCHEMA_CACHE.put(clazz.getName(), schema);
return schema;
}
/**
* Remove a schema
*
* @param clazz Object class
* @param Object type
*/
public static void remove(Class clazz) {
SCHEMA_CACHE.remove(clazz.getName());
}
/**
* Clear schema cache
*/
public static void clear() {
SCHEMA_CACHE.clear();
}
}