<commit_before><?php
abstract class NpAbstractCache
{
	protected $cache;
	protected $prefix;
	protected $timeout;
	
	public function __construct($prefix,$timeout)
	{
		$this->prefix=$prefix;
		$this->timeout=$timeout;
	}
	
	public abstract function inc($key, $value);
	public abstract function dec($key, $value);
	public abstract function get($key);
	public abstract function set($key,$value,$timeout);
	public abstract function delete($key);
}

class NpMemcache extends NpAbstractCache
{
	public function __destruct()
	{
		if($this->cache!==null) {
			$this->cache->close();
			$this->cache=null;
		}
	}

	public function connect($host, $port)
	{
		$this->cache=new Memcache();
		return $this->cache->pconnect($host,$port);
	}

	public function inc($key, $value=1)
	{
		$key=$this->prefix.$key;
		$result=$this->cache->increment($key, $value);
		if(!$result) {
			if($this->cache->set($key, $value))
				$result=$value;
		}
		return $result;
	}

	public function dec($key, $value=1)
	{
		$key=$this->prefix.$key;
		$result=$this->cache->decrement($key, $value);
		if(!$result) {
			if($this->cache->set($key, 0-$value))
				$result=0-$value;
		}
		return $result;
	}

	public function get($key)
	{
		$key=$this->prefix.$key;
		return $this->cache->get($key);
	}

	public function set($key,$value,$timeout=0)
	{
		$key=$this->prefix.$key;
		if($timeout==0) {
			$timeout=$this->timeout;
			if($timeout==0)
				return $this->cache->set($key, $value);
		}
		return $this->cache->set($key, $value, 0, $timeout);
	}

	public function delete($key)
	{
		$key=$this->prefix.$key;
		return $this->cache->delete($key);
	}
}

class NpMemcached extends NpMemcache
{
	public function __destruct()
	{		
	}
	
	public function connect($host, $port)
	{
		$this->cache=new Memcached();
		return $this->cache->addServer($host,$port);
	}

	public function set($key,$value,$timeout=0)
	{
		$key=$this->prefix.$key;
		if($timeout==0){
			$timeout=$this->timeout;
			if($timeout==0)
				return $this->cache->set($key, $value);
		}
		return $this->cache->set($key, $value, $timeout);
	}
}

class NpRedis extends NpAbstractCache
{
	public function __destruct()
	{
		if($this->cache!==null) {
			$this->cache->close();
			$this->cache=null;
		}
	}

	public function connect($host, $port)
	{
		$this->cache=new Redis();
		return $this->cache->pconnect($host,$port);
	}

	public function inc($key, $value=1)
	{
		$key=$this->prefix.$key;
		return $this->cache->incrBy($key, $value);
	}

	public function dec($key, $value=1)
	{
		$key=$this->prefix.$key;
		return $this->cache->decrBy($key, $value);
	}

	public function get($key)
	{
		$key=$this->prefix.$key;
		return $this->cache->get($key);
	}

	public function set($key,$value,$timeout=0)
	{
		$key=$this->prefix.$key;
		if($timeout==0){
			$timeout=$this->timeout;
			if($timeout==0)
				return $this->cache->set($key, $value);
		}
		return $this->cache->setex($key, $timeout, $value);
	}

	public function delete($key)
	{
		$key=$this->prefix.$key;
		return $this->cache->delete($key);
	}
}
<commit_msg>add: method setNoExists for NpCache<commit_after><?php
abstract class NpAbstractCache
{
	protected $cache;
	protected $prefix;
	protected $timeout;
	
	public function __construct($prefix,$timeout)
	{
		$this->prefix=$prefix;
		$this->timeout=$timeout;
	}
	
	public abstract function inc($key, $value);
	public abstract function dec($key, $value);
	public abstract function get($key);
	public abstract function set($key,$value,$timeout);
	public abstract function setNoExists($key,$value,$timeout);
	public abstract function delete($key);
}

class NpMemcache extends NpAbstractCache
{
	public function __destruct()
	{
		if($this->cache!==null) {
			$this->cache->close();
			$this->cache=null;
		}
	}

	public function connect($host, $port)
	{
		$this->cache=new Memcache();
		return $this->cache->pconnect($host,$port);
	}

	public function inc($key, $value=1)
	{
		$key=$this->prefix.$key;
		$result=$this->cache->increment($key, $value);
		if(!$result) {
			if($this->cache->set($key, $value))
				$result=$value;
		}
		return $result;
	}

	public function dec($key, $value=1)
	{
		$key=$this->prefix.$key;
		$result=$this->cache->decrement($key, $value);
		if(!$result) {
			if($this->cache->set($key, 0-$value))
				$result=0-$value;
		}
		return $result;
	}

	public function get($key)
	{
		$key=$this->prefix.$key;
		return $this->cache->get($key);
	}

	public function set($key,$value,$timeout=0)
	{
		$key=$this->prefix.$key;
		if($timeout==0) {
			$timeout=$this->timeout;
			if($timeout==0)
				return $this->cache->set($key, $value);
		}
		return $this->cache->set($key, $value, 0, $timeout);
	}
	
	public function setNoExists($key,$value,$timeout=0)
	{
		$key=$this->prefix.$key;
		if($timeout==0) {
			$timeout=$this->timeout;
			if($timeout==0)
				return $this->cache->add($key, $value);
		}
		return $this->cache->add($key, $value, 0, $timeout);
	}

	public function delete($key)
	{
		$key=$this->prefix.$key;
		return $this->cache->delete($key);
	}
}

class NpMemcached extends NpMemcache
{
	public function __destruct()
	{		
	}
	
	public function connect($host, $port)
	{
		$this->cache=new Memcached();
		return $this->cache->addServer($host,$port);
	}

	public function set($key,$value,$timeout=0)
	{
		$key=$this->prefix.$key;
		if($timeout==0){
			$timeout=$this->timeout;
			if($timeout==0)
				return $this->cache->set($key, $value);
		}
		return $this->cache->set($key, $value, $timeout);
	}
	
	public function setNoExists($key,$value,$timeout=0)
	{
		$key=$this->prefix.$key;
		if($timeout==0) {
			$timeout=$this->timeout;
			if($timeout==0)
				return $this->cache->add($key, $value);
		}
		return $this->cache->add($key, $value, $timeout);
	}
}

class NpRedis extends NpAbstractCache
{
	public function __destruct()
	{
		if($this->cache!==null) {
			$this->cache->close();
			$this->cache=null;
		}
	}

	public function connect($host, $port)
	{
		$this->cache=new Redis();
		return $this->cache->pconnect($host,$port);
	}

	public function inc($key, $value=1)
	{
		$key=$this->prefix.$key;
		return $this->cache->incrBy($key, $value);
	}

	public function dec($key, $value=1)
	{
		$key=$this->prefix.$key;
		return $this->cache->decrBy($key, $value);
	}

	public function get($key)
	{
		$key=$this->prefix.$key;
		return $this->cache->get($key);
	}

	public function set($key,$value,$timeout=0)
	{
		$key=$this->prefix.$key;
		if($timeout==0){
			$timeout=$this->timeout;
			if($timeout==0)
				return $this->cache->set($key, $value);
		}
		return $this->cache->setex($key, $timeout, $value);
	}
	
	public function setNoExists($key,$value,$timeout=0)
	{
		$key=$this->prefix.$key;
		if($timeout==0)
			$timeout=$this->timeout;
		$result=$this->cache->setnx($key, $value);
		if($result && $timeout>0)
			$this->cache->setTimeout($timeout);
		return $result;
	}

	public function delete($key)
	{
		$key=$this->prefix.$key;
		return $this->cache->delete($key);
	}
}

{'fraction_non_alphanumeric': 0.20941652224147891, 'fraction_numerical': 0.006065857885615251, 'mean_word_length': 4.405932864949258, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 152, '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': '7522728', 'n_tokens_mistral': 2789, 'n_tokens_neox': 2532, 'n_words': 444}