Search in sources :

Example 1 with SerializingTranscoder

use of net.spy.memcached.transcoders.SerializingTranscoder in project qi4j-sdk by Qi4j.

the class MemcacheImpl method get.

@Override
public T get(String key) {
    Object value = client.get(prefix(key), new SerializingTranscoder());
    client.touch(prefix(key), expiration);
    if (value == null) {
        return null;
    }
    return valueType.cast(value);
}
Also used : SerializingTranscoder(net.spy.memcached.transcoders.SerializingTranscoder)

Example 2 with SerializingTranscoder

use of net.spy.memcached.transcoders.SerializingTranscoder in project druid by druid-io.

the class MemcachedCacheBenchmark method setUp.

@Override
protected void setUp() throws Exception {
    SerializingTranscoder transcoder = new SerializingTranscoder(// 50 MB
    50 * 1024 * 1024);
    // disable compression
    transcoder.setCompressionThreshold(Integer.MAX_VALUE);
    client = new MemcachedClient(new ConnectionFactoryBuilder().setProtocol(ConnectionFactoryBuilder.Protocol.BINARY).setHashAlg(DefaultHashAlgorithm.FNV1A_64_HASH).setLocatorType(ConnectionFactoryBuilder.Locator.CONSISTENT).setDaemon(true).setFailureMode(FailureMode.Retry).setTranscoder(transcoder).setShouldOptimize(true).build(), AddrUtil.getAddresses(hosts));
    cache = new MemcachedCache(Suppliers.<ResourceHolder<MemcachedClientIF>>ofInstance(StupidResourceHolder.create(client)), new MemcachedCacheConfig() {

        @Override
        public String getMemcachedPrefix() {
            return "druid-memcached-benchmark";
        }

        @Override
        public int getTimeout() {
            return 30000;
        }

        @Override
        public int getExpiration() {
            return 3600;
        }
    }, MemcachedCacheTest.NOOP_MONITOR);
    randBytes = new byte[objectSize * 1024];
    new Random(0).nextBytes(randBytes);
}
Also used : SerializingTranscoder(net.spy.memcached.transcoders.SerializingTranscoder) ConnectionFactoryBuilder(net.spy.memcached.ConnectionFactoryBuilder) Random(java.util.Random) MemcachedClient(net.spy.memcached.MemcachedClient) ResourceHolder(io.druid.collections.ResourceHolder) StupidResourceHolder(io.druid.collections.StupidResourceHolder)

Example 3 with SerializingTranscoder

use of net.spy.memcached.transcoders.SerializingTranscoder in project qi4j-sdk by Qi4j.

the class MemcacheImpl method remove.

@Override
public T remove(String key) {
    String prefixedKey = prefix(key);
    Object old = client.get(prefixedKey, new SerializingTranscoder());
    if (old != null) {
        client.delete(prefixedKey);
    }
    return valueType.cast(old);
}
Also used : SerializingTranscoder(net.spy.memcached.transcoders.SerializingTranscoder)

Aggregations

SerializingTranscoder (net.spy.memcached.transcoders.SerializingTranscoder)3 ResourceHolder (io.druid.collections.ResourceHolder)1 StupidResourceHolder (io.druid.collections.StupidResourceHolder)1 Random (java.util.Random)1 ConnectionFactoryBuilder (net.spy.memcached.ConnectionFactoryBuilder)1 MemcachedClient (net.spy.memcached.MemcachedClient)1