<commit_before><?php
/*
Plugin Name: APC Cache
Plugin URI: http://virgingroupdigital.wordpress.com
Description: Caches most database traffic at the expense of some accuracy
Version: 0.3
Author: <NAME> <<EMAIL>>
Author URI: http://phpir.com/
*/

// Verify APC is installed, suggested by @ozh
if( !function_exists( 'apc_exists' ) ) {
   yourls_die( 'This plugin requires the APC extension: http://pecl.php.net/package/APC' );
}

if(!defined('APC_WRITE_CACHE_TIMEOUT')) {
	define('APC_WRITE_CACHE_TIMEOUT', 120);
}
if(!defined('APC_READ_CACHE_TIMEOUT')) {
	define('APC_READ_CACHE_TIMEOUT', 360);
}
define('APC_CACHE_LOG_INDEX', 'cachelogindex');
define('APC_CACHE_LOG_TIMER', 'cachelogtimer');
define('APC_CACHE_ALL_OPTIONS', 'cache-get_all_options');
if(!defined('APC_CACHE_LONG_TIMEOUT')) {
	define('APC_CACHE_LONG_TIMEOUT', 86400);
}

yourls_add_action( 'pre_get_keyword', 'apc_cache_pre_get_keyword' );
yourls_add_filter( 'get_keyword_infos', 'apc_cache_get_keyword_infos' );
yourls_add_filter( 'shunt_update_clicks', 'apc_cache_shunt_update_clicks' );
yourls_add_filter( 'shunt_log_redirect', 'apc_cache_shunt_log_redirect' );
yourls_add_filter( 'shunt_all_options', 'apc_cache_shunt_all_options' );
yourls_add_filter( 'get_all_options', 'apc_cache_get_all_options' );

/**
 * Return cached options is available
 *
 * @param bool $false 
 * @return bool true
 */
function apc_cache_shunt_all_options($false) {
	global $ydb; 
	
	$key = APC_CACHE_ALL_OPTIONS; 
	if(apc_exists($key)) {
		$ydb->option = apc_fetch($key);
		return true;
	} 
	
	return false;
}

/**
 * Cache all_options data. 
 *
 * @param array $options 
 * @return array options
 */
function apc_cache_get_all_options($option) {
	apc_store(APC_CACHE_ALL_OPTIONS, $option, APC_READ_CACHE_TIMEOUT);
	return $option;
}

/**
 * If the URL data is in the cache, stick it back into the global DB object. 
 * 
 * @param string $args
 */
function apc_cache_pre_get_keyword($args) {
	global $ydb;
	$keyword = $args[0];
	
	// Lookup in cache
	if(apc_exists($keyword)) {
		$ydb->infos[$keyword] = apc_fetch($keyword); 	
	}
}

/**
 * 
 * Store the keyword info in the cache
 * @param array $info
 * @param string $keyword
 */
function apc_cache_get_keyword_infos($info, $keyword) {
	// Store in cache
	apc_store($keyword, $info, APC_READ_CACHE_TIMEOUT);
	return $info;
}
<commit_msg>Adding a hook to clear cache on plugin activation<commit_after><?php
/*
Plugin Name: APC Cache
Plugin URI: http://virgingroupdigital.wordpress.com
Description: Caches most database traffic at the expense of some accuracy
Version: 0.3
Author: <NAME> <<EMAIL>>
Author URI: http://phpir.com/
*/

// Verify APC is installed, suggested by @ozh
if( !function_exists( 'apc_exists' ) ) {
   yourls_die( 'This plugin requires the APC extension: http://pecl.php.net/package/APC' );
}

if(!defined('APC_WRITE_CACHE_TIMEOUT')) {
	define('APC_WRITE_CACHE_TIMEOUT', 120);
}
if(!defined('APC_READ_CACHE_TIMEOUT')) {
	define('APC_READ_CACHE_TIMEOUT', 360);
}
define('APC_CACHE_LOG_INDEX', 'cachelogindex');
define('APC_CACHE_LOG_TIMER', 'cachelogtimer');
define('APC_CACHE_ALL_OPTIONS', 'cache-get_all_options');
if(!defined('APC_CACHE_LONG_TIMEOUT')) {
	define('APC_CACHE_LONG_TIMEOUT', 86400);
}

yourls_add_action( 'pre_get_keyword', 'apc_cache_pre_get_keyword' );
yourls_add_filter( 'get_keyword_infos', 'apc_cache_get_keyword_infos' );
yourls_add_filter( 'shunt_update_clicks', 'apc_cache_shunt_update_clicks' );
yourls_add_filter( 'shunt_log_redirect', 'apc_cache_shunt_log_redirect' );
yourls_add_filter( 'shunt_all_options', 'apc_cache_shunt_all_options' );
yourls_add_filter( 'get_all_options', 'apc_cache_get_all_options' );
yourls_add_filter( 'activated_plugin', 'apc_cache_plugin_statechange' );
yourls_add_filter( 'deactivated_plugin', 'apc_cache_plugin_statechange' );

/**
 * Return cached options is available
 *
 * @param bool $false 
 * @return bool true
 */
function apc_cache_shunt_all_options($false) {
	global $ydb; 
	
	$key = APC_CACHE_ALL_OPTIONS; 
	if(apc_exists($key)) {
		$ydb->option = apc_fetch($key);
		return true;
	} 
	
	return false;
}

/**
 * Cache all_options data. 
 *
 * @param array $options 
 * @return array options
 */
function apc_cache_get_all_options($option) {
	apc_store(APC_CACHE_ALL_OPTIONS, $option, APC_READ_CACHE_TIMEOUT);
	return $option;
}

/**
 * Clear the options cache if a plugin is activated or deactivated
 *
 * @param string $plugin 
 */
function apc_cache_plugin_statechange($plugin) {
        apc_delete(APC_CACHE_ALL_OPTIONS);
}

/**
 * If the URL data is in the cache, stick it back into the global DB object. 
 * 
 * @param string $args
 */
function apc_cache_pre_get_keyword($args) {
	global $ydb;
	$keyword = $args[0];
	
	// Lookup in cache
	if(apc_exists($keyword)) {
		$ydb->infos[$keyword] = apc_fetch($keyword); 	
	}
}

/**
 * 
 * Store the keyword info in the cache
 * @param array $info
 * @param string $keyword
 */
function apc_cache_get_keyword_infos($info, $keyword) {
	// Store in cache
	apc_store($keyword, $info, APC_READ_CACHE_TIMEOUT);
	return $info;
}

{'fraction_non_alphanumeric': 0.1321463897131553, 'fraction_numerical': 0.005539070227497527, 'mean_word_length': 5.860244233378562, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 13, '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': '3193777', 'n_tokens_mistral': 1909, 'n_tokens_neox': 1853, 'n_words': 377}