<commit_before>package org.xdi.service.cache;

import net.spy.memcached.AddrUtil;
import net.spy.memcached.DefaultConnectionFactory;
import net.spy.memcached.MemcachedClient;
import org.jboss.seam.annotations.*;
import org.jboss.seam.cache.CacheProvider;
import org.jboss.seam.log.Log;

import static org.jboss.seam.ScopeType.APPLICATION;

/**
 * @author yuriyz on 02/02/2017.
 */
@Name("memcachedProvider")
@Scope(APPLICATION)
@AutoCreate
@Startup
public class MemcachedProvider extends CacheProvider<MemcachedClient> {

    @Logger
    private Log log;

    @In(required = true)
    private MemcachedConfiguration memcachedConfiguration;

    private MemcachedClient client;

    @Create
    public void create() {
        log.debug("Starting MemcachedProvider...");
        try {
            client = new MemcachedClient(
                    new DefaultConnectionFactory(memcachedConfiguration.getMaxOperationQueueLength(), memcachedConfiguration.getBufferSize()),
                    AddrUtil.getAddresses(memcachedConfiguration.getServers()));
            log.debug("MemcachedProvider started");
        } catch (Exception e) {
            throw new IllegalStateException("Error starting MemcachedProvider", e);
        }
    }

    @Destroy
    public void destroy() {
        log.debug("Destroying MemcachedProvider");

        try {
            client.shutdown();
        } catch (RuntimeException e) {
            throw new IllegalStateException("Error destroying MemcachedProvider", e);
        }
    }

    @Override
    public MemcachedClient getDelegate() {
        return client;
    }

    @Override
    public Object get(String region, String key) {
        return client.get(key);
    }

    @Override // it is so weird but we use as workaround "region" field to pass "expiration" for put operation
    public void put(String expirationInSeconds, String key, Object object) {
        client.set(key, putExpiration(expirationInSeconds), object);
    }

    private int putExpiration(String expirationInSeconds) {
        try {
            return Integer.parseInt(expirationInSeconds);
        } catch (Exception e) {
            return memcachedConfiguration.getPutExpiration();
        }
    }

    @Override
    public void remove(String region, String key) {
        client.delete(key);
    }

    @Override
    public void clear() {
        throw new UnsupportedOperationException();
    }
}<commit_msg>memcached.flush()<commit_after>package org.xdi.service.cache;

import net.spy.memcached.AddrUtil;
import net.spy.memcached.DefaultConnectionFactory;
import net.spy.memcached.MemcachedClient;
import org.jboss.seam.annotations.*;
import org.jboss.seam.cache.CacheProvider;
import org.jboss.seam.log.Log;

import static org.jboss.seam.ScopeType.APPLICATION;

/**
 * @author yuriyz on 02/02/2017.
 */
@Name("memcachedProvider")
@Scope(APPLICATION)
@AutoCreate
@Startup
public class MemcachedProvider extends CacheProvider<MemcachedClient> {

    @Logger
    private Log log;

    @In(required = true)
    private MemcachedConfiguration memcachedConfiguration;

    private MemcachedClient client;

    @Create
    public void create() {
        log.debug("Starting MemcachedProvider...");
        try {
            client = new MemcachedClient(
                    new DefaultConnectionFactory(memcachedConfiguration.getMaxOperationQueueLength(), memcachedConfiguration.getBufferSize()),
                    AddrUtil.getAddresses(memcachedConfiguration.getServers()));
            log.debug("MemcachedProvider started");
        } catch (Exception e) {
            throw new IllegalStateException("Error starting MemcachedProvider", e);
        }
    }

    @Destroy
    public void destroy() {
        log.debug("Destroying MemcachedProvider");

        try {
            client.shutdown();
        } catch (RuntimeException e) {
            throw new IllegalStateException("Error destroying MemcachedProvider", e);
        }
    }

    @Override
    public MemcachedClient getDelegate() {
        return client;
    }

    @Override
    public Object get(String region, String key) {
        return client.get(key);
    }

    @Override // it is so weird but we use as workaround "region" field to pass "expiration" for put operation
    public void put(String expirationInSeconds, String key, Object object) {
        client.set(key, putExpiration(expirationInSeconds), object);
    }

    private int putExpiration(String expirationInSeconds) {
        try {
            return Integer.parseInt(expirationInSeconds);
        } catch (Exception e) {
            return memcachedConfiguration.getPutExpiration();
        }
    }

    @Override
    public void remove(String region, String key) {
        client.delete(key);
    }

    @Override
    public void clear() {
        client.flush()
    }
}
{'fraction_non_alphanumeric': 0.09352965574450435, 'fraction_numerical': 0.0033181252592285357, 'mean_word_length': 2.8738955823293173, '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': '4940739', 'n_tokens_mistral': 1322, 'n_tokens_neox': 1258, 'n_words': 308}