<commit_before><?php
	/*
		Neptune Content Management System
		Cache Management! - /system/core/cache.php

		This will be the object to manage external caches
		(such as APC, memcached or XCache).
	*/

	// Checking if NepNep is defined, for security purposes.	
	if(!defined('NepNep')) {
		die('NO U');
	}
	
	// if the cache expiry variable is not set, obviously no expiry is needed
	if(NeptuneCore::var_get('cache', 'expire')) {
		$expire = NeptuneCore::var_get('cache', 'expire');
	} else {
		$expire = false;
	}
	
	// time to determine which cache has been selected
	// (atm supporting several at once will complicate things)
	// APC will be preferred for simplicity
	switch(NeptuneCore::var_get('cache', 'type')) {
		case 'apc':
			$cache = new apc_neptune();
			define('cache_available', true, true);
		break;
		
		case 'memcached':
			if(!(NeptuneCore::var_get('cache', 'memcached'))) {
				$cache = new memcached_neptune();
				define('cache_available', true, true);
			}
			else {
				// we need memcached servers to function if this is enabled, so throw error.
				die('FATAL ERROR: You haven\'t set any memcached servers in config!');
			}
		break;
		
		case 'xcache':
			$cache = new xcache_neptune();
			define('cache_available', true, true);
		break;
	}

	// APC Class, interfaces the alternative
	//  PHP Cache to store values persistantly
	//  which should reduce the need for SQL
	//  queries pretty significantly.
	//  Cannot be used in conjunction with Xcache.
	class apc_neptune {
		// the set function
		function set($var, $val) {
			global $expire;
			apc_store($var, $val, $expire);
		}
		// the get function
		function get($var) {
			return apc_get($var);
		}
		// the delete function
		function delete($var) {
			apc_delete($var);
		}
		// the function to flush the cache
		function flush() {
			return apc_clear_cache('user');
		}
	}
/*	
	// currently broken - DO NOT USE
	class memcached_neptune {
		private static $memcached;
		private static $memcache;
		$memcached = new Memcached();
		$memcached->addServers(NeptuneCore::var_get('cache', 'memcached'));
		function set($var) {
			global $memcached, $memcache;
		}
		function get($var) {
			global $memcached, $memcache;
		}
		function delete($var) {
			global $memcached, $memcache;
		}
		function flush($var) {
			global $memcached, $memcache;
		}
	}
	
	// currently broken - DO NOT USE
	class xcache_neptune {
		private static $memcached;
		function set($var) {
		}
		function get($var) {
		}
		function delete($var) {
		}
		function flush($var) {
		}
	}
*/
?><commit_msg>Implemented XCache, memcached, eAccelerator. Fixed compliancy.<commit_after><?php
	/*
		Neptune Content Management System
		Cache Management! - /system/core/cache.php

		This will be the object to manage external caches
		(such as APC, memcached or XCache).
	*/

	// Checking if NepNep is defined, for security purposes.	
	if(!defined('NepNep')) {
		die('NO U');
	}
	
	// No need to overdeclare NeptuneCore if it's already set
	if(!isset($NeptuneCore)) {
		$NeptuneCore = new NeptuneCore();
	}
	
	// time to determine which cache has been selected
	// (atm supporting several at once will complicate things)
	// APC will be preferred for simplicity
	switch($NeptuneCore->var_get('cache', 'type')) {
		case 'apc':
			$cache = new apc_neptune();
			define('cache_available', true, true);
		break;
		
		case 'memcached':
			if(!($NeptuneCore->var_get('cache', 'memcached'))) {
				$cache = new memcached_neptune();
				define('cache_available', true, true);
			}
			else {
				// we need memcached servers to function if this is enabled, so throw error.
				die('FATAL ERROR: You haven\'t set any memcached servers in config!');
			}
		break;
		
		case 'xcache':
			$cache = new xcache_neptune();
			define('cache_available', true, true);
		break;
	}

	// APC Class, interfaces the alternative
	//  PHP Cache to store values persistantly
	//  which should reduce the need for SQL
	//  queries pretty significantly.
	//  Cannot be used in conjunction with Xcache.
	class apc_neptune {
		// the set function
		function set($var, $val, $expire=0) {
			apc_store($var, $val, $expire);
		}
		// the get function
		function get($var) {
			return apc_fetch($var);
		}
		// the delete function
		function delete($var) {
			apc_delete($var);
		}
		// the function to flush the cache
		function flush() {
			return apc_clear_cache('user');
		}
	}
	
	// XCache Class, interfaces with XCache which 
	//  is also a rather nice cache.
	class xcache_neptune {
		private static $memcached;
		function set($var, $val, $expire=0) {
			xcache_set($var, $val, $expire);
		}
		function get($var) {
			return xcache_get($var);
		}
		function delete($var) {
			xcache_unset($var);
		}
		function flush($var) {
			// seems like there's no workaround -- for now
		}
	}
	
	// eAccelerator Cache Class.
	//  nobody really uses eA, but it's included
	//  just-in-case.
	class eaccelerator_neptune {
		function set($var, $val, $expire=0) {
			eaccelerator_put($var, $val, $expire);
		}
		function get($var) {
			return eaccelerator_get($var);
		}
		function delete($var) {
			eaccelerator_rm($var);
		}
		function flush($var) {
			foreach(eaccelerator_list_keys() as $var => $val) {
				eaccelerator_rm($variable['name']);
			}
		}
	}

	// memcached class -- potentially usable WITH a PHP accelerator.
	class memcached_neptune {
		// memcached uses a pseudo-class, so we must use that
		//   additionally it stores variables within each instance
		//   so ensuring there is only one is more important than
		//   before.
		private static $memcached;
		private static function init() {
			global $NeptuneCore;
			self::$memcached = new Memcached();
			self::$memcached->addServers($NeptuneCore->var_get('cache', 'memcached'));
		}
		function set($var, $val, $expire) {
			if(!self::$memcached) {
				self::init();
			}
			self::$memcached->set($var, $val, $expire);
		}
		function get($var) {
			if(!self::$memcached) {
				self::init();
			}
			return self::$memcached->get($var);
		}
		function delete($var) {
			if(!self::$memcached) {
				self::init();
			}
			self::$memcached->delete($var);
		}
		function flush($var) {
			if(!self::$memcached) {
				self::init();
			}
			self::$memcached->flush();
		}
	}

?>
{'fraction_non_alphanumeric': 0.13777064955894147, 'fraction_numerical': 0.00048115477145148355, 'mean_word_length': 3.3486750348675036, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 15, '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': '1740367', 'n_tokens_mistral': 2396, 'n_tokens_neox': 2101, 'n_words': 596}