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

com.litongjava.tio.utils.cache.j2cache.J2Cache Maven / Gradle / Ivy

There is a newer version: 3.7.3.v202400213-RELEASE
Show newest version
package com.litongjava.tio.utils.cache.j2cache;

import java.io.Serializable;
import java.util.Collection;
import java.util.Map;

import com.litongjava.tio.utils.cache.AbsCache;

import net.oschina.j2cache.CacheChannel;
import net.oschina.j2cache.CacheObject;

/**
 * 红薯家的j2cache
 * @author tanyaowu
 *
 */
public class J2Cache extends AbsCache {
  public J2Cache(String cacheName) {
    super(cacheName);
  }

  private static CacheChannel getChannel() {
    CacheChannel cache = net.oschina.j2cache.J2Cache.getChannel();
    return cache;
  }

  @Override
  public void clear() {
    CacheChannel cache = getChannel();
    cache.clear(cacheName);
  }

  @Override
  public Serializable _get(String key) {
    CacheChannel cache = getChannel();
    CacheObject cacheObject = cache.get(cacheName, key);
    if (cacheObject != null) {
      return (Serializable) cacheObject.getValue();
    }
    return null;
  }

  @Override
  public Collection keys() {
    CacheChannel cache = getChannel();
    return cache.keys(cacheName);
  }

  @Override
  public Collection keysCollection() {
    return getChannel().keys(cacheName);
  }

  @Override
  public void put(String key, Serializable value) {
    CacheChannel cache = getChannel();
    cache.set(cacheName, key, value);
  }

  @Override
  public void remove(String key) {
    CacheChannel cache = getChannel();
    cache.evict(cacheName, key);
  }

  @Override
  public void putTemporary(String key, Serializable value) {
    throw new RuntimeException("不支持防缓存穿透");
  }

  @Override
  public long ttl(String key) {
    throw new RuntimeException("不支持ttl");
  }

  @Override
  public Map asMap() {
//    Collection keys = getChannel().keys(cacheName);
//    Map map = getChannel().get(cacheName, keys);
//    return map;
    return null;
    
  }

  @Override
  public long size() {
    CacheChannel channel = getChannel();
    return channel.keys(cacheName).size();
  }

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy