All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.fnklabs.draenei.orm.CacheUtils Maven / Gradle / Ivy

There is a newer version: 0.8.3
Show newest version
package com.fnklabs.draenei.orm;

import org.apache.commons.lang3.StringUtils;
import org.apache.ignite.cache.CacheAtomicityMode;
import org.apache.ignite.cache.CacheMemoryMode;
import org.apache.ignite.cache.CacheMode;
import org.apache.ignite.cache.eviction.lru.LruEvictionPolicy;
import org.apache.ignite.configuration.CacheConfiguration;
import org.jetbrains.annotations.NotNull;

/**
 * Cache utils
 */
public class CacheUtils {
    /**
     * Return cache name for specified entity class
     *
     * @param clazz Entity class
     *
     * @return Cache name
     */
    public static String getCacheName(@NotNull Class clazz) {
        return StringUtils.lowerCase(clazz.getName());
    }

    public static  CacheConfiguration getCacheConfiguration(@NotNull DataProvider dataProvider) {
        if (dataProvider instanceof CacheableDataProvider) {
            return ((CacheableDataProvider) dataProvider).getCacheConfiguration();
        }

        return CacheUtils.getDefaultCacheConfiguration(dataProvider.getEntityClass());
    }

    /**
     * Get default cache configuration for specified entity class
     *
     * @param entityClass Entity class
     * @param      Entity class typ
     *
     * @return Cache Configuration for specified entity class
     */
    public static  CacheConfiguration getDefaultCacheConfiguration(Class entityClass) {
        CacheConfiguration cacheCfg = new CacheConfiguration<>(getCacheName(entityClass));
        cacheCfg.setBackups(1);
        cacheCfg.setCacheMode(CacheMode.PARTITIONED);
        cacheCfg.setAtomicityMode(CacheAtomicityMode.ATOMIC);
        cacheCfg.setOffHeapMaxMemory(0);
        cacheCfg.setReadThrough(false);
        cacheCfg.setWriteThrough(false);
        cacheCfg.setMemoryMode(CacheMemoryMode.ONHEAP_TIERED);
        cacheCfg.setEvictionPolicy(new LruEvictionPolicy<>(10000));
        return cacheCfg;
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy