net.oschina.j2cache.J2Cache Java Examples

The following examples show how to use net.oschina.j2cache.J2Cache. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: J2CacheRegionFactory.java    From J2Cache with Apache License 2.0 5 votes vote down vote up
@Override
public void start(Settings settings, Properties properties) throws CacheException {
    this.settings = settings;
    if (this.channel == null) {
        this.channel = J2Cache.getChannel();
    }
}
 
Example #2
Source File: J2CacheRegionFactoryTest.java    From J2Cache with Apache License 2.0 5 votes vote down vote up
private Map getCacheValue(String region, String key) {
    try {
        Object item = J2Cache.getChannel()
                .get(region, key)
                .getValue();
        if (item != null)
            return (Map) BeanUtils.getPropertyDescriptor(item.getClass(), "value")
                    .getReadMethod()
                    .invoke(item);
    } catch (IllegalAccessException | InvocationTargetException e) {
        LOG.error(e.getMessage(), e);
    }
    return null;
}
 
Example #3
Source File: J2CacheRegionFactory.java    From J2Cache with Apache License 2.0 5 votes vote down vote up
@Override
public void start(SessionFactoryOptions settings, Properties properties) throws CacheException {
    this.settings = settings;
    if (this.channel == null) {
        this.channel = J2Cache.getChannel();
    }
}
 
Example #4
Source File: J2CacheRegionFactoryTest.java    From J2Cache with Apache License 2.0 5 votes vote down vote up
private Map getCacheValue(String region, String key) {
    try {
        Object item = J2Cache.getChannel()
                .get(region, key)
                .getValue();
        if (item != null)
            return (Map) BeanUtils.getPropertyDescriptor(item.getClass(), "value")
                    .getReadMethod()
                    .invoke(item);
    } catch (IllegalAccessException | InvocationTargetException e) {
        LOG.error(e.getMessage(), e);
    }
    return null;
}
 
Example #5
Source File: J2cacheImpl.java    From jboot with Apache License 2.0 5 votes vote down vote up
@Override
public void refresh(String cacheName, Object key) {
    if (sendEvictCmdMethod == null) {
        synchronized (this) {
            if (sendEvictCmdMethod == null) {
                sendEvictCmdMethod = getSendEvictCmdMethod();
            }
        }
    }
    try {
        sendEvictCmdMethod.invoke(J2Cache.getChannel(), cacheName, key);
    } catch (Exception e) {
        e.printStackTrace();
    }
}
 
Example #6
Source File: J2cacheImpl.java    From jboot with Apache License 2.0 5 votes vote down vote up
@Override
public void refresh(String cacheName) {
    if (sendClearCmdMethod == null) {
        synchronized (this) {
            if (sendClearCmdMethod == null) {
                sendClearCmdMethod = getSendClearCmdMethod();
            }
        }
    }
    try {
        sendClearCmdMethod.invoke(J2Cache.getChannel(), cacheName);
    } catch (Exception e) {
        e.printStackTrace();
    }
}
 
Example #7
Source File: J2cacheImpl.java    From jboot with Apache License 2.0 5 votes vote down vote up
@Override
public List getNames() {
    Collection<CacheChannel.Region> regions = J2Cache.getChannel().getL1Provider().regions();
    return regions != null && !regions.isEmpty()
            ? regions.stream().map(CacheChannel.Region::getName).collect(Collectors.toList())
            : null;
}
 
Example #8
Source File: J2CacheSpringCacheManageAdapter.java    From J2Cache with Apache License 2.0 4 votes vote down vote up
@Override
protected Cache getMissingCache(String name) {
    CacheChannel cacheChannel = j2CacheBuilder == null ? J2Cache.getChannel() : j2CacheBuilder.getChannel();
    return new J2CacheSpringCacheAdapter(allowNullValues, cacheChannel, name);
}
 
Example #9
Source File: J2CacheProvider.java    From J2Cache with Apache License 2.0 4 votes vote down vote up
@Override
public Cache buildCache(String regionName, Properties properties)
        throws CacheException {
    return new J2HibernateCache(regionName, J2Cache.getChannel());
}
 
Example #10
Source File: J2CacheProvider.java    From J2Cache with Apache License 2.0 4 votes vote down vote up
@Override
public void stop() {
    J2Cache.getChannel().close();
}
 
Example #11
Source File: J2cacheImpl.java    From jboot with Apache License 2.0 4 votes vote down vote up
@Override
public <T> T get(String cacheName, Object key) {
    CacheObject cacheObject = J2Cache.getChannel().get(cacheName, key.toString(), false);
    return cacheObject != null ? (T) cacheObject.getValue() : null;
}
 
Example #12
Source File: J2cacheImpl.java    From jboot with Apache License 2.0 4 votes vote down vote up
@Override
public void put(String cacheName, Object key, Object value) {
    J2Cache.getChannel().set(cacheName, key.toString(), value);
}
 
Example #13
Source File: J2cacheImpl.java    From jboot with Apache License 2.0 4 votes vote down vote up
@Override
public void put(String cacheName, Object key, Object value, int liveSeconds) {
    J2Cache.getChannel().set(cacheName, key.toString(), value, liveSeconds);
}
 
Example #14
Source File: J2cacheImpl.java    From jboot with Apache License 2.0 4 votes vote down vote up
@Override
public void remove(String cacheName, Object key) {
    J2Cache.getChannel().evict(cacheName, key.toString());
}
 
Example #15
Source File: J2cacheImpl.java    From jboot with Apache License 2.0 4 votes vote down vote up
@Override
public void removeAll(String cacheName) {
    J2Cache.getChannel().clear(cacheName);
}
 
Example #16
Source File: J2cacheImpl.java    From jboot with Apache License 2.0 4 votes vote down vote up
@Override
public List getKeys(String cacheName) {
    Collection keys = J2Cache.getChannel().keys(cacheName);
    return keys != null ? new ArrayList(keys) : null;
}