class MemcacheClientFactoryImpl implements CacheClientFactory {

    @Override
    public CacheClient create(final List<InetSocketAddress> addrs, final CacheConfiguration conf) throws IOException {
        // currently its works because this factory creates clients with the same connection settings, only memcached
        // addresses can be changed
        if (connectionFactory == null) {
            ConnectionFactoryBuilder builder = new ConnectionFactoryBuilder();

            if (conf.isConsistentHashing()) {
                builder.setHashAlg(DefaultHashAlgorithm.KETAMA_HASH);
                builder.setLocatorType(Locator.CONSISTENT);
            }

            builder.setProtocol(conf.isUseBinaryProtocol() ? Protocol.BINARY : Protocol.TEXT);
            if (conf.getOperationTimeout() != null) {
                builder.setOpTimeout(conf.getOperationTimeout());
            }

            if (conf instanceof SpymemcachedConfiguration) {
                setProviderSpecificSettings(builder, (SpymemcachedConfiguration) conf);
            }

            connectionFactory = builder.build();
        }

        return new MemcacheClientWrapper(new MemcachedClient(connectionFactory, addrs));
    }

}