<commit_before>package com.x.base.core.project.cache;

import java.util.ArrayList;
import java.util.List;
import java.util.Optional;

import org.apache.commons.lang3.StringUtils;

import com.x.base.core.project.cache.Cache.CacheCategory;
import com.x.base.core.project.cache.Cache.CacheKey;
import com.x.base.core.project.config.Config;
import com.x.base.core.project.jaxrs.WrapClearCacheRequest;
import com.x.base.core.project.logger.Logger;
import com.x.base.core.project.logger.LoggerFactory;
import com.x.base.core.project.tools.ListTools;
import com.x.base.core.project.tools.StringTools;

public abstract class CacheManager {

	private static final Logger LOGGER = LoggerFactory.getLogger(CacheManager.class);

	private CacheManager() {
	}

	private static Cache cache;

	private static String name = StringTools.uniqueToken();

	public static void init(String name) throws Exception {
		CacheManager.name = name;
		cache();
	}

	private static synchronized Cache cache() throws Exception {
		if (null == cache) {
			if (StringUtils.equals(Config.cache().getType(), Cache.TYPE_REDIS)) {
				cache = new CacheRedisImpl(name);
//			} else if (StringUtils.equals(Config.cache().getType(), Cache.TYPE_EHCACHE)) {
//				cache = new CacheEhcacheImpl(name);
			} else {
				cache = new CacheGuavaImpl(Cache.TYPE_GUAVA);
			}
		}
		return cache;
	}

	public static void put(CacheCategory category, CacheKey key, Object o) {
		try {
			cache().put(category, key, o);
		} catch (Exception e) {
			LOGGER.error(e);
		}
	}

	public static Optional<Object> get(CacheCategory category, CacheKey key) {
		try {
			return cache().get(category, key);
		} catch (Exception e) {
			LOGGER.error(e);
		}
		return Optional.empty();
	}

	public static void shutdown() {
		try {
			if (null != cache) {
				cache.shutdown();
			}
		} catch (Exception e) {
			LOGGER.error(e);
		}
	}

	public static void receive(WrapClearCacheRequest wi) {
		try {
			if (null != cache) {
				cache.receive(wi);
			}<commit_msg>修复保存到缓存对象未校验null的问题<commit_after>package com.x.base.core.project.cache;

import java.util.ArrayList;
import java.util.List;
import java.util.Optional;

import org.apache.commons.lang3.StringUtils;

import com.x.base.core.project.cache.Cache.CacheCategory;
import com.x.base.core.project.cache.Cache.CacheKey;
import com.x.base.core.project.config.Config;
import com.x.base.core.project.jaxrs.WrapClearCacheRequest;
import com.x.base.core.project.logger.Logger;
import com.x.base.core.project.logger.LoggerFactory;
import com.x.base.core.project.tools.ListTools;
import com.x.base.core.project.tools.StringTools;

public abstract class CacheManager {

	private static final Logger LOGGER = LoggerFactory.getLogger(CacheManager.class);

	private CacheManager() {
	}

	private static Cache cache;

	private static String name = StringTools.uniqueToken();

	public static void init(String name) throws Exception {
		CacheManager.name = name;
		cache();
	}

	private static synchronized Cache cache() throws Exception {
		if (null == cache) {
			if (StringUtils.equals(Config.cache().getType(), Cache.TYPE_REDIS)) {
				cache = new CacheRedisImpl(name);
//			} else if (StringUtils.equals(Config.cache().getType(), Cache.TYPE_EHCACHE)) {
//				cache = new CacheEhcacheImpl(name);
			} else {
				cache = new CacheGuavaImpl(Cache.TYPE_GUAVA);
			}
		}
		return cache;
	}

	public static void put(CacheCategory category, CacheKey key, Object o) {
		try {
			if(o != null) {
				cache().put(category, key, o);
			}
		} catch (Exception e) {
			LOGGER.error(e);
		}
	}

	public static Optional<Object> get(CacheCategory category, CacheKey key) {
		try {
			return cache().get(category, key);
		} catch (Exception e) {
			LOGGER.error(e);
		}
		return Optional.empty();
	}

	public static void shutdown() {
		try {
			if (null != cache) {
				cache.shutdown();
			}
		} catch (Exception e) {
			LOGGER.error(e);
		}
	}

	public static void receive(WrapClearCacheRequest wi) {
		try {
			if (null != cache) {
				cache.receive(wi);
			}
{'fraction_non_alphanumeric': 0.1298830554864394, 'fraction_numerical': 0.0004976362279173924, 'mean_word_length': 3.932515337423313, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4234895', 'n_tokens_mistral': 1453, 'n_tokens_neox': 1327, 'n_words': 288}