Version 4.0.13.1
This commit is contained in:
1 parent
f9e857d255
commit
c6a86f0d9b
7517 files changed
+597400
-668041
No files matched your search
@@ -0,0 +1,119 @@
|
||||
<?php
|
||||
/**
|
||||
* @brief APC Caching Class
|
||||
* @author <a href='http://www.invisionpower.com'>Invision Power Services, Inc.</a>
|
||||
* @copyright (c) 2001 - SVN_YYYY Invision Power Services, Inc.
|
||||
* @license http://www.invisionpower.com/legal/standards/
|
||||
* @package IPS Social Suite
|
||||
* @since 17 Sept 2013
|
||||
* @version SVN_VERSION_NUMBER
|
||||
*/
|
||||
|
||||
namespace IPS\Data\Cache;
|
||||
|
||||
/* To prevent PHP errors (extending class does not exist) revealing path */
|
||||
if ( !defined( '\IPS\SUITE_UNIQUE_KEY' ) )
|
||||
{
|
||||
header( ( isset( $_SERVER['SERVER_PROTOCOL'] ) ? $_SERVER['SERVER_PROTOCOL'] : 'HTTP/1.0' ) . ' 403 Forbidden' );
|
||||
exit;
|
||||
}
|
||||
|
||||
/**
|
||||
* APC Storage Class
|
||||
*/
|
||||
class _Apc extends \IPS\Data\Cache
|
||||
{
|
||||
/**
|
||||
* Server supports this method?
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public static function supported()
|
||||
{
|
||||
return function_exists('apc_fetch');
|
||||
}
|
||||
|
||||
/**
|
||||
* Abstract Method: Get
|
||||
*
|
||||
* @param string $key Key
|
||||
* @return string Value from the _datastore
|
||||
*/
|
||||
protected function get( $key )
|
||||
{
|
||||
if( isset( $this->cache[ $key ] ) )
|
||||
{
|
||||
\IPS\Log::i( LOG_DEBUG )->setIpAddress( $_SERVER['REMOTE_ADDR'] )->write( "Get {$key} from APC (already loaded)", 'cache' );
|
||||
return $this->cache[ $key ];
|
||||
}
|
||||
|
||||
\IPS\Log::i( LOG_DEBUG )->setIpAddress( $_SERVER['REMOTE_ADDR'] )->write( "Get {$key} from APC", 'cache' );
|
||||
|
||||
$this->cache[ $key ] = apc_fetch( \IPS\SUITE_UNIQUE_KEY . '_' . $key );
|
||||
return $this->cache[ $key ];
|
||||
}
|
||||
|
||||
/**
|
||||
* Abstract Method: Set
|
||||
*
|
||||
* @param string $key Key
|
||||
* @param string $value Value
|
||||
* @return bool
|
||||
*/
|
||||
protected function set( $key, $value )
|
||||
{
|
||||
\IPS\Log::i( LOG_DEBUG )->setIpAddress( $_SERVER['REMOTE_ADDR'] )->write( "Set {$key} in APC", 'cache' );
|
||||
return (bool) apc_store( \IPS\SUITE_UNIQUE_KEY . '_' . $key, $value );
|
||||
}
|
||||
|
||||
/**
|
||||
* Abstract Method: Exists?
|
||||
*
|
||||
* @param string $key Key
|
||||
* @return bool
|
||||
*/
|
||||
protected function exists( $key )
|
||||
{
|
||||
if( isset( $this->cache[ $key ] ) )
|
||||
{
|
||||
\IPS\Log::i( LOG_DEBUG )->setIpAddress( $_SERVER['REMOTE_ADDR'] )->write( "Check exists {$key} from APC (already loaded)", 'cache' );
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
\IPS\Log::i( LOG_DEBUG )->setIpAddress( $_SERVER['REMOTE_ADDR'] )->write( "Check exists {$key} from APC", 'cache' );
|
||||
|
||||
$result = apc_fetch( \IPS\SUITE_UNIQUE_KEY . '_' . $key, $exists );
|
||||
if ( $exists )
|
||||
{
|
||||
$this->cache[ $key ] = $result;
|
||||
return TRUE;
|
||||
}
|
||||
else
|
||||
{
|
||||
return FALSE;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Abstract Method: Delete
|
||||
*
|
||||
* @param string $key Key
|
||||
* @return bool
|
||||
*/
|
||||
protected function delete( $key )
|
||||
{
|
||||
\IPS\Log::i( LOG_DEBUG )->setIpAddress( $_SERVER['REMOTE_ADDR'] )->write( "Delete {$key} from APC", 'cache' );
|
||||
return (bool) apc_delete( \IPS\SUITE_UNIQUE_KEY . '_' . $key );
|
||||
}
|
||||
|
||||
/**
|
||||
* Abstract Method: Clear All Caches
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function clearAll()
|
||||
{
|
||||
\IPS\Log::i( LOG_DEBUG )->setIpAddress( $_SERVER['REMOTE_ADDR'] )->write( "Flush all caches from APC", 'cache' );
|
||||
apc_clear_cache();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,127 @@
|
||||
<?php
|
||||
/**
|
||||
* @brief eAccelerator Cache Class
|
||||
* @author <a href='http://www.invisionpower.com'>Invision Power Services, Inc.</a>
|
||||
* @copyright (c) 2001 - SVN_YYYY Invision Power Services, Inc.
|
||||
* @license http://www.invisionpower.com/legal/standards/
|
||||
* @package IPS Social Suite
|
||||
* @since 17 Sept 2013
|
||||
* @version SVN_VERSION_NUMBER
|
||||
*/
|
||||
|
||||
namespace IPS\Data\Cache;
|
||||
|
||||
/* To prevent PHP errors (extending class does not exist) revealing path */
|
||||
if ( !defined( '\IPS\SUITE_UNIQUE_KEY' ) )
|
||||
{
|
||||
header( ( isset( $_SERVER['SERVER_PROTOCOL'] ) ? $_SERVER['SERVER_PROTOCOL'] : 'HTTP/1.0' ) . ' 403 Forbidden' );
|
||||
exit;
|
||||
}
|
||||
|
||||
/**
|
||||
* eAccelerator Storage Class
|
||||
*/
|
||||
class _Eaccelerator extends \IPS\Data\Cache
|
||||
{
|
||||
/**
|
||||
* Server supports this method?
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public static function supported()
|
||||
{
|
||||
return function_exists('eaccelerator_get');
|
||||
}
|
||||
|
||||
/**
|
||||
* Abstract Method: Get
|
||||
*
|
||||
* @param string $key Key
|
||||
* @return string Value from the _datastore
|
||||
*/
|
||||
protected function get( $key )
|
||||
{
|
||||
if( isset( $this->cache[ $key ] ) )
|
||||
{
|
||||
\IPS\Log::i( LOG_DEBUG )->setIpAddress( $_SERVER['REMOTE_ADDR'] )->write( "Get {$key} from eAccelerator (already loaded)", 'cache' );
|
||||
return $this->cache[ $key ];
|
||||
}
|
||||
|
||||
\IPS\Log::i( LOG_DEBUG )->setIpAddress( $_SERVER['REMOTE_ADDR'] )->write( "Get {$key} from eAccelerator", 'cache' );
|
||||
|
||||
$this->cache[ $key ] = eaccelerator_get( \IPS\SUITE_UNIQUE_KEY . '_' . $key );
|
||||
return $this->cache[ $key ];
|
||||
}
|
||||
|
||||
/**
|
||||
* Abstract Method: Set
|
||||
*
|
||||
* @param string $key Key
|
||||
* @param string $value Value
|
||||
* @return bool
|
||||
*/
|
||||
protected function set( $key, $value )
|
||||
{
|
||||
\IPS\Log::i( LOG_DEBUG )->setIpAddress( $_SERVER['REMOTE_ADDR'] )->write( "Set {$key} in eAccelerator", 'cache' );
|
||||
|
||||
eaccelerator_lock( \IPS\SUITE_UNIQUE_KEY . '_' . $key );
|
||||
$result = (bool) eaccelerator_put( \IPS\SUITE_UNIQUE_KEY . '_' . $key, $value );
|
||||
eaccelerator_unlock( \IPS\SUITE_UNIQUE_KEY . '_' . $key );
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Abstract Method: Exists?
|
||||
*
|
||||
* @param string $key Key
|
||||
* @return bool
|
||||
*/
|
||||
protected function exists( $key )
|
||||
{
|
||||
if( isset( $this->cache[ $key ] ) )
|
||||
{
|
||||
\IPS\Log::i( LOG_DEBUG )->setIpAddress( $_SERVER['REMOTE_ADDR'] )->write( "Check exists {$key} from eAccelerator (already loaded)", 'cache' );
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
\IPS\Log::i( LOG_DEBUG )->setIpAddress( $_SERVER['REMOTE_ADDR'] )->write( "Check exists {$key} from eAccelerator", 'cache' );
|
||||
return (bool) $this->get( $key );
|
||||
}
|
||||
|
||||
/**
|
||||
* Abstract Method: Delete
|
||||
*
|
||||
* @param string $key Key
|
||||
* @return bool
|
||||
*/
|
||||
protected function delete( $key )
|
||||
{
|
||||
\IPS\Log::i( LOG_DEBUG )->setIpAddress( $_SERVER['REMOTE_ADDR'] )->write( "Delete {$key} from eAccelerator", 'cache' );
|
||||
return (bool) eaccelerator_rm( \IPS\SUITE_UNIQUE_KEY . '_' . $key );
|
||||
}
|
||||
|
||||
/**
|
||||
* Destructor
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function __destruct()
|
||||
{
|
||||
if( function_exists( 'eaccelerator_gc' ) )
|
||||
{
|
||||
\IPS\Log::i( LOG_DEBUG )->setIpAddress( $_SERVER['REMOTE_ADDR'] )->write( "eAccelerator GC", 'cache' );
|
||||
eaccelerator_gc();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Abstract Method: Clear All Caches
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function clearAll()
|
||||
{
|
||||
\IPS\Log::i( LOG_DEBUG )->setIpAddress( $_SERVER['REMOTE_ADDR'] )->write( "Flush all caches from eAccelerator (not implemented)", 'cache' );
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,237 @@
|
||||
<?php
|
||||
/**
|
||||
* @brief Memcache Cache Class
|
||||
* @author <a href='http://www.invisionpower.com'>Invision Power Services, Inc.</a>
|
||||
* @copyright (c) 2001 - SVN_YYYY Invision Power Services, Inc.
|
||||
* @license http://www.invisionpower.com/legal/standards/
|
||||
* @package IPS Social Suite
|
||||
* @since 17 Sept 2013
|
||||
* @version SVN_VERSION_NUMBER
|
||||
*/
|
||||
|
||||
namespace IPS\Data\Cache;
|
||||
|
||||
/* To prevent PHP errors (extending class does not exist) revealing path */
|
||||
if ( !defined( '\IPS\SUITE_UNIQUE_KEY' ) )
|
||||
{
|
||||
header( ( isset( $_SERVER['SERVER_PROTOCOL'] ) ? $_SERVER['SERVER_PROTOCOL'] : 'HTTP/1.0' ) . ' 403 Forbidden' );
|
||||
exit;
|
||||
}
|
||||
|
||||
/**
|
||||
* Memcache Cache Class
|
||||
*/
|
||||
class _Memcache extends \IPS\Data\Cache
|
||||
{
|
||||
/**
|
||||
* Server supports this method?
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public static function supported()
|
||||
{
|
||||
return ( class_exists( 'Memcached' ) OR class_exists( 'Memcache' ) );
|
||||
}
|
||||
|
||||
/**
|
||||
* Configuration
|
||||
*
|
||||
* @param array $configuration Existing settings
|
||||
* @return array \IPS\Helpers\Form\FormAbstract elements
|
||||
*/
|
||||
public static function configuration( $configuration )
|
||||
{
|
||||
return array(
|
||||
'servers' => new \IPS\Helpers\Form\Stack( 'datastore_memcache_servers', isset( $configuration['servers'] ) ? $configuration['servers'] : array(), FALSE, array( 'placeholder' => '127.0.0.1:11211' ), function( $val )
|
||||
{
|
||||
if ( \IPS\Request::i()->cache_method === 'Memcache' )
|
||||
{
|
||||
if ( empty( $val ) )
|
||||
{
|
||||
throw new \DomainException( 'datastore_memcache_servers_err' );
|
||||
}
|
||||
else
|
||||
{
|
||||
$test = new \IPS\Data\Cache\Memcache( array( 'servers' => $val ) );
|
||||
if ( $test->link->getStats() === FALSE )
|
||||
{
|
||||
throw new \DomainException( 'datastore_memcache_servers_err2' );
|
||||
}
|
||||
}
|
||||
}
|
||||
} )
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Connection resource
|
||||
*/
|
||||
protected $link = null;
|
||||
|
||||
/**
|
||||
* @brief Keys that do not exist
|
||||
*/
|
||||
protected $doesNotExist = array();
|
||||
|
||||
/**
|
||||
* Get the server link
|
||||
*
|
||||
* @return \Memcache|\Memcached
|
||||
*/
|
||||
protected function _getLink()
|
||||
{
|
||||
if( class_exists( 'Memcached' ) )
|
||||
{
|
||||
return new \Memcached;
|
||||
}
|
||||
else
|
||||
{
|
||||
return new \Memcache;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* @param array $configuration Configuration
|
||||
* @return void
|
||||
*/
|
||||
public function __construct( $configuration )
|
||||
{
|
||||
/* Connect and add the servers that are defined to the pool */
|
||||
$this->link = $this->_getLink();
|
||||
|
||||
$configuration['servers'] = ( !is_array( $configuration['servers'] ) ) ? array( $configuration['servers'] ) : $configuration['servers'];
|
||||
|
||||
foreach( $configuration['servers'] as $server )
|
||||
{
|
||||
$exploded = explode( ':', $server );
|
||||
$this->link->addServer( $exploded[0], isset( $exploded[1] ) ? $exploded[1] : 11211 );
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Abstract Method: Get
|
||||
*
|
||||
* @param string $key Key
|
||||
* @return string Value from the _datastore
|
||||
*/
|
||||
protected function get( $key )
|
||||
{
|
||||
if( !isset( $this->cache[ $key ] ) )
|
||||
{
|
||||
$value = $this->link->get( \IPS\SUITE_UNIQUE_KEY . '_' . $key );
|
||||
|
||||
if( method_exists( $this->link, 'getResultCode' ) and $this->link->getResultCode() == \Memcached::RES_NOTFOUND )
|
||||
{
|
||||
$this->doesNotExist[] = $key;
|
||||
throw new \OutOfRangeException;
|
||||
}
|
||||
|
||||
$this->cache[ $key ] = $value;
|
||||
}
|
||||
|
||||
return $this->cache[ $key ];
|
||||
}
|
||||
|
||||
/**
|
||||
* Abstract Method: Set
|
||||
*
|
||||
* @param string $key Key
|
||||
* @param string $value Value
|
||||
* @return bool
|
||||
*/
|
||||
protected function set( $key, $value )
|
||||
{
|
||||
if ( in_array( $key, $this->doesNotExist ) )
|
||||
{
|
||||
unset( $this->doesNotExist[ array_search( $key, $this->doesNotExist ) ] );
|
||||
}
|
||||
$this->cache[ $key ] = $value;
|
||||
|
||||
return (bool) $this->link->set( \IPS\SUITE_UNIQUE_KEY . '_' . $key, $value );
|
||||
}
|
||||
|
||||
/**
|
||||
* Abstract Method: Exists?
|
||||
*
|
||||
* @param string $key Key
|
||||
* @return bool
|
||||
*/
|
||||
protected function exists( $key )
|
||||
{
|
||||
if ( in_array( $key, $this->doesNotExist ) )
|
||||
{
|
||||
return FALSE;
|
||||
}
|
||||
elseif ( isset( $this->cache[ $key ] ) )
|
||||
{
|
||||
return TRUE;
|
||||
}
|
||||
else
|
||||
{
|
||||
$value = $this->link->get( \IPS\SUITE_UNIQUE_KEY . '_' . $key );
|
||||
|
||||
if( method_exists( $this->link, 'getResultCode' ) )
|
||||
{
|
||||
if ( $this->link->getResultCode() == \Memcached::RES_NOTFOUND )
|
||||
{
|
||||
$this->doesNotExist[] = $key;
|
||||
return FALSE;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if ( $value === FALSE )
|
||||
{
|
||||
$this->doesNotExist[] = $key;
|
||||
return FALSE;
|
||||
}
|
||||
}
|
||||
|
||||
$this->cache[ $key ] = $value;
|
||||
return TRUE;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Abstract Method: Delete
|
||||
*
|
||||
* @param string $key Key
|
||||
* @return bool
|
||||
*/
|
||||
protected function delete( $key )
|
||||
{
|
||||
return (bool) $this->link->delete( \IPS\SUITE_UNIQUE_KEY . '_' . $key );
|
||||
}
|
||||
|
||||
/**
|
||||
* Destructor
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function __destruct()
|
||||
{
|
||||
if( $this->link )
|
||||
{
|
||||
if( method_exists( $this->link, 'quit' ) )
|
||||
{
|
||||
$this->link->quit();
|
||||
}
|
||||
elseif( method_exists( $this->link, 'close' ) )
|
||||
{
|
||||
$this->link->close();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Abstract Method: Clear All Caches
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function clearAll()
|
||||
{
|
||||
$this->link->flush();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,153 @@
|
||||
<?php
|
||||
/**
|
||||
* @brief Dummy Cache Class
|
||||
* @author <a href='http://www.invisionpower.com'>Invision Power Services, Inc.</a>
|
||||
* @copyright (c) 2001 - SVN_YYYY Invision Power Services, Inc.
|
||||
* @license http://www.invisionpower.com/legal/standards/
|
||||
* @package IPS Social Suite
|
||||
* @since 17 Sept 2013
|
||||
* @version SVN_VERSION_NUMBER
|
||||
*/
|
||||
|
||||
namespace IPS\Data\Cache;
|
||||
|
||||
/* To prevent PHP errors (extending class does not exist) revealing path */
|
||||
if ( !defined( '\IPS\SUITE_UNIQUE_KEY' ) )
|
||||
{
|
||||
header( ( isset( $_SERVER['SERVER_PROTOCOL'] ) ? $_SERVER['SERVER_PROTOCOL'] : 'HTTP/1.0' ) . ' 403 Forbidden' );
|
||||
exit;
|
||||
}
|
||||
|
||||
/**
|
||||
* Dummy Storage Class
|
||||
*/
|
||||
class _None extends \IPS\Data\Cache
|
||||
{
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* @param array $configuration Configuration
|
||||
* @return void
|
||||
* @note Overridden for performance reasons
|
||||
*/
|
||||
public function __construct( $configuration )
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* Magic Method: Get
|
||||
*
|
||||
* @param string $key Key
|
||||
* @return string Value from the _datastore
|
||||
* @throws \OutOfRangeException
|
||||
* @note Overridden for performance reasons
|
||||
*/
|
||||
public function __get( $key )
|
||||
{
|
||||
throw new \OutOfRangeException;
|
||||
}
|
||||
|
||||
/**
|
||||
* Magic Method: Set
|
||||
*
|
||||
* @param string $key Key
|
||||
* @param string $value Value
|
||||
* @return void
|
||||
* @note Overridden for performance reasons
|
||||
*/
|
||||
public function __set( $key, $value )
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* Magic Method: Isset
|
||||
*
|
||||
* @param string $key Key
|
||||
* @return bool
|
||||
* @note Overridden for performance reasons
|
||||
*/
|
||||
public function __isset( $key )
|
||||
{
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
/**
|
||||
* Magic Method: Unset
|
||||
*
|
||||
* @param string $key Key
|
||||
* @return void
|
||||
* @note Overridden for performance reasons
|
||||
*/
|
||||
public function __unset( $key )
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* Server supports this method?
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public static function supported()
|
||||
{
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
/**
|
||||
* Abstract Method: Get
|
||||
*
|
||||
* @param string $key Key
|
||||
* @return string Value from the _datastore
|
||||
*/
|
||||
protected function get( $key )
|
||||
{
|
||||
throw new \RuntimeException;
|
||||
}
|
||||
|
||||
/**
|
||||
* Abstract Method: Set
|
||||
*
|
||||
* @param string $key Key
|
||||
* @param string $value Value
|
||||
* @return bool
|
||||
*/
|
||||
protected function set( $key, $value )
|
||||
{
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
/**
|
||||
* Abstract Method: Exists?
|
||||
*
|
||||
* @param string $key Key
|
||||
* @return bool
|
||||
*/
|
||||
protected function exists( $key )
|
||||
{
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
/**
|
||||
* Abstract Method: Delete
|
||||
*
|
||||
* @param string $key Key
|
||||
* @return bool
|
||||
*/
|
||||
protected function delete( $key )
|
||||
{
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
/**
|
||||
* Abstract Method: Clear All Caches
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function clearAll()
|
||||
{
|
||||
try
|
||||
{
|
||||
\IPS\Db::i()->delete( 'core_cache' );
|
||||
}
|
||||
catch ( \IPS\Db\Exception $e ){}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,197 @@
|
||||
<?php
|
||||
/**
|
||||
* @brief Redis Cache Class
|
||||
* @author <a href='http://www.invisionpower.com'>Invision Power Services, Inc.</a>
|
||||
* @copyright (c) 2001 - SVN_YYYY Invision Power Services, Inc.
|
||||
* @license http://www.invisionpower.com/legal/standards/
|
||||
* @package IPS Social Suite
|
||||
* @since 18 Oct 2013
|
||||
* @version SVN_VERSION_NUMBER
|
||||
*/
|
||||
|
||||
namespace IPS\Data\Cache;
|
||||
|
||||
/* To prevent PHP errors (extending class does not exist) revealing path */
|
||||
if ( !defined( '\IPS\SUITE_UNIQUE_KEY' ) )
|
||||
{
|
||||
header( ( isset( $_SERVER['SERVER_PROTOCOL'] ) ? $_SERVER['SERVER_PROTOCOL'] : 'HTTP/1.0' ) . ' 403 Forbidden' );
|
||||
exit;
|
||||
}
|
||||
|
||||
/**
|
||||
* Redis Cache Class
|
||||
*/
|
||||
class _Redis extends \IPS\Data\Cache
|
||||
{
|
||||
/**
|
||||
* Server supports this method?
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public static function supported()
|
||||
{
|
||||
return class_exists('Redis');
|
||||
}
|
||||
|
||||
/**
|
||||
* Configuration
|
||||
*
|
||||
* @param array $configuration Existing settings
|
||||
* @return array \IPS\Helpers\Form\FormAbstract elements
|
||||
*/
|
||||
public static function configuration( $configuration )
|
||||
{
|
||||
return array(
|
||||
'server' => new \IPS\Helpers\Form\Text( 'server_host', isset( $configuration['server'] ) ? $configuration['server'] : '', FALSE, array( 'placeholder' => '127.0.0.1' ), function( $val )
|
||||
{
|
||||
if ( \IPS\Request::i()->cache_method === 'Redis' and empty( $val ) )
|
||||
{
|
||||
throw new \DomainException( 'datastore_redis_servers_err' );
|
||||
}
|
||||
} ),
|
||||
'port' => new \IPS\Helpers\Form\Number( 'server_port', isset( $configuration['port'] ) ? $configuration['port'] : NULL, FALSE, array( 'placeholder' => '6379' ), function( $val )
|
||||
{
|
||||
if ( \IPS\Request::i()->cache_method === 'Redis' AND $val AND ( $val < 0 OR $val > 65535 ) )
|
||||
{
|
||||
throw new \DomainException( 'datastore_redis_servers_err' );
|
||||
}
|
||||
} ),
|
||||
'password' => new \IPS\Helpers\Form\Password( 'server_password', isset( $configuration['password'] ) ? $configuration['password'] : '', FALSE ),
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Connection resource
|
||||
*/
|
||||
protected $link = null;
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* @param array $configuration Configuration
|
||||
* @return void
|
||||
*/
|
||||
public function __construct( $configuration )
|
||||
{
|
||||
/* Connect to server */
|
||||
try
|
||||
{
|
||||
$this->link = new \Redis;
|
||||
|
||||
if( $this->link->connect( $configuration['server'], $configuration['port'] ) === FALSE )
|
||||
{
|
||||
$this->link = NULL;
|
||||
}
|
||||
else
|
||||
{
|
||||
if( $configuration['password'] )
|
||||
{
|
||||
if( $this->link->auth( $configuration['password'] ) === FALSE )
|
||||
{
|
||||
$this->link = NULL;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if( $this->link !== NULL )
|
||||
{
|
||||
$this->link->setOption( \Redis::OPT_SERIALIZER, \Redis::SERIALIZER_PHP );
|
||||
}
|
||||
|
||||
\IPS\Log::i( LOG_DEBUG )->setIpAddress( $_SERVER['REMOTE_ADDR'] )->write( "Connected to Redis", 'cache' );
|
||||
}
|
||||
catch( \RedisException $e )
|
||||
{
|
||||
$this->link = NULL;
|
||||
\IPS\Log::i( LOG_DEBUG )->setIpAddress( $_SERVER['REMOTE_ADDR'] )->write( "Connection to Redis failed", 'cache' );
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Abstract Method: Get
|
||||
*
|
||||
* @param string $key Key
|
||||
* @return string Value from the _datastore
|
||||
*/
|
||||
protected function get( $key )
|
||||
{
|
||||
if( isset( $this->cache[ $key ] ) )
|
||||
{
|
||||
\IPS\Log::i( LOG_DEBUG )->setIpAddress( $_SERVER['REMOTE_ADDR'] )->write( "Get {$key} from Redis (already loaded)", 'cache' );
|
||||
return $this->cache[ $key ];
|
||||
}
|
||||
|
||||
\IPS\Log::i( LOG_DEBUG )->setIpAddress( $_SERVER['REMOTE_ADDR'] )->write( "Get {$key} from Redis", 'cache' );
|
||||
|
||||
$this->cache[ $key ] = $this->link->get( \IPS\SUITE_UNIQUE_KEY . '_' . $key );
|
||||
return $this->cache[ $key ];
|
||||
}
|
||||
|
||||
/**
|
||||
* Abstract Method: Set
|
||||
*
|
||||
* @param string $key Key
|
||||
* @param string $value Value
|
||||
* @return bool
|
||||
*/
|
||||
protected function set( $key, $value )
|
||||
{
|
||||
\IPS\Log::i( LOG_DEBUG )->setIpAddress( $_SERVER['REMOTE_ADDR'] )->write( "Set {$key} in Redis", 'cache' );
|
||||
return (bool) $this->link->set( \IPS\SUITE_UNIQUE_KEY . '_' . $key, $value );
|
||||
}
|
||||
|
||||
/**
|
||||
* Abstract Method: Exists?
|
||||
*
|
||||
* @param string $key Key
|
||||
* @return bool
|
||||
*/
|
||||
protected function exists( $key )
|
||||
{
|
||||
if( isset( $this->cache[ $key ] ) )
|
||||
{
|
||||
\IPS\Log::i( LOG_DEBUG )->setIpAddress( $_SERVER['REMOTE_ADDR'] )->write( "Check exists {$key} from Redis (already loaded)", 'cache' );
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
\IPS\Log::i( LOG_DEBUG )->setIpAddress( $_SERVER['REMOTE_ADDR'] )->write( "Check exists {$key} from Redis", 'cache' );
|
||||
return $this->link->exists( $key );
|
||||
}
|
||||
|
||||
/**
|
||||
* Abstract Method: Delete
|
||||
*
|
||||
* @param string $key Key
|
||||
* @return bool
|
||||
*/
|
||||
protected function delete( $key )
|
||||
{
|
||||
\IPS\Log::i( LOG_DEBUG )->setIpAddress( $_SERVER['REMOTE_ADDR'] )->write( "Delete {$key} from Redis", 'cache' );
|
||||
return (bool) $this->link->delete( \IPS\SUITE_UNIQUE_KEY . '_' . $key );
|
||||
}
|
||||
|
||||
/**
|
||||
* Destructor
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function __destruct()
|
||||
{
|
||||
if( $this->link )
|
||||
{
|
||||
\IPS\Log::i( LOG_DEBUG )->setIpAddress( $_SERVER['REMOTE_ADDR'] )->write( "Disconnect from Redis", 'cache' );
|
||||
|
||||
$this->link->close();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Abstract Method: Clear All Caches
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function clearAll()
|
||||
{
|
||||
\IPS\Log::i( LOG_DEBUG )->setIpAddress( $_SERVER['REMOTE_ADDR'] )->write( "Flush all caches from Redis (not implemented)", 'cache' );
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,125 @@
|
||||
<?php
|
||||
/**
|
||||
* @brief Test Cache Class
|
||||
* @author <a href='http://www.invisionpower.com'>Invision Power Services, Inc.</a>
|
||||
* @copyright (c) 2001 - SVN_YYYY Invision Power Services, Inc.
|
||||
* @license http://www.invisionpower.com/legal/standards/
|
||||
* @package IPS Social Suite
|
||||
* @since 7 Jan 2015
|
||||
* @version SVN_VERSION_NUMBER
|
||||
*/
|
||||
|
||||
namespace IPS\Data\Cache;
|
||||
|
||||
/* To prevent PHP errors (extending class does not exist) revealing path */
|
||||
if ( !defined( '\IPS\SUITE_UNIQUE_KEY' ) )
|
||||
{
|
||||
header( ( isset( $_SERVER['SERVER_PROTOCOL'] ) ? $_SERVER['SERVER_PROTOCOL'] : 'HTTP/1.0' ) . ' 403 Forbidden' );
|
||||
exit;
|
||||
}
|
||||
|
||||
/**
|
||||
* Test Cache Class
|
||||
*/
|
||||
class _Test extends \IPS\Data\Cache
|
||||
{
|
||||
/**
|
||||
* Server supports this method?
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public static function supported()
|
||||
{
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
/**
|
||||
* Configuration
|
||||
*
|
||||
* @param array $configuration Existing settings
|
||||
* @return array \IPS\Helpers\Form\FormAbstract elements
|
||||
*/
|
||||
public static function configuration( $configuration )
|
||||
{
|
||||
return array( 'path' => new \IPS\Helpers\Form\Text( 'datastore_test_path', ( isset( $configuration['path'] ) ) ? $configuration['path'] : '', FALSE ) );
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Storage Path
|
||||
*/
|
||||
public $_path;
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* @param array $configuration Configuration
|
||||
* @return void
|
||||
*/
|
||||
public function __construct( $configuration )
|
||||
{
|
||||
$this->_path = rtrim( $configuration['path'], '/' );
|
||||
}
|
||||
|
||||
/**
|
||||
* Abstract Method: Get
|
||||
*
|
||||
* @param string $key Key
|
||||
* @return string Value from the _datastore
|
||||
*/
|
||||
protected function get( $key )
|
||||
{
|
||||
return file_get_contents( $this->_path . '/' . $key . '.txt' );
|
||||
}
|
||||
|
||||
/**
|
||||
* Abstract Method: Set
|
||||
*
|
||||
* @param string $key Key
|
||||
* @param string $value Value
|
||||
* @return bool
|
||||
*/
|
||||
protected function set( $key, $value )
|
||||
{
|
||||
$return = \file_put_contents( $this->_path . '/' . $key . '.txt', $value );
|
||||
chmod( $this->_path . '/' . $key . '.txt', \IPS\IPS_FILE_PERMISSION );
|
||||
return $return;
|
||||
}
|
||||
|
||||
/**
|
||||
* Abstract Method: Exists?
|
||||
*
|
||||
* @param string $key Key
|
||||
* @return bool
|
||||
*/
|
||||
protected function exists( $key )
|
||||
{
|
||||
return file_exists( $this->_path . '/' . $key . '.txt' );
|
||||
}
|
||||
|
||||
/**
|
||||
* Abstract Method: Delete
|
||||
*
|
||||
* @param string $key Key
|
||||
* @return bool
|
||||
*/
|
||||
protected function delete( $key )
|
||||
{
|
||||
return @unlink( $this->_path . '/' . $key . '.txt' );
|
||||
}
|
||||
|
||||
/**
|
||||
* Abstract Method: Clear All Caches
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function clearAll()
|
||||
{
|
||||
foreach ( new \DirectoryIterator( $this->_path ) as $file )
|
||||
{
|
||||
if ( !$file->isDot() and $file != 'index.html' )
|
||||
{
|
||||
@unlink( $this->_path . '/' . $file );
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,110 @@
|
||||
<?php
|
||||
/**
|
||||
* @brief Wincache Cache Class
|
||||
* @author <a href='http://www.invisionpower.com'>Invision Power Services, Inc.</a>
|
||||
* @copyright (c) 2001 - SVN_YYYY Invision Power Services, Inc.
|
||||
* @license http://www.invisionpower.com/legal/standards/
|
||||
* @package IPS Social Suite
|
||||
* @since 17 Sept 2013
|
||||
* @version SVN_VERSION_NUMBER
|
||||
*/
|
||||
|
||||
namespace IPS\Data\Cache;
|
||||
|
||||
/* To prevent PHP errors (extending class does not exist) revealing path */
|
||||
if ( !defined( '\IPS\SUITE_UNIQUE_KEY' ) )
|
||||
{
|
||||
header( ( isset( $_SERVER['SERVER_PROTOCOL'] ) ? $_SERVER['SERVER_PROTOCOL'] : 'HTTP/1.0' ) . ' 403 Forbidden' );
|
||||
exit;
|
||||
}
|
||||
|
||||
/**
|
||||
* Wincache Storage Class
|
||||
*/
|
||||
class _Wincache extends \IPS\Data\Cache
|
||||
{
|
||||
/**
|
||||
* Server supports this method?
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public static function supported()
|
||||
{
|
||||
return function_exists('wincache_ucache_get');
|
||||
}
|
||||
|
||||
/**
|
||||
* Abstract Method: Get
|
||||
*
|
||||
* @param string $key Key
|
||||
* @return string Value from the _datastore
|
||||
*/
|
||||
protected function get( $key )
|
||||
{
|
||||
if( isset( $this->cache[ $key ] ) )
|
||||
{
|
||||
\IPS\Log::i( LOG_DEBUG )->setIpAddress( $_SERVER['REMOTE_ADDR'] )->write( "Get {$key} from Wincache (already loaded)", 'cache' );
|
||||
return $this->cache[ $key ];
|
||||
}
|
||||
|
||||
\IPS\Log::i( LOG_DEBUG )->setIpAddress( $_SERVER['REMOTE_ADDR'] )->write( "Get {$key} from Wincache", 'cache' );
|
||||
|
||||
$this->cache[ $key ] = wincache_ucache_get( \IPS\SUITE_UNIQUE_KEY . '_' . $key );
|
||||
return $this->cache[ $key ];
|
||||
}
|
||||
|
||||
/**
|
||||
* Abstract Method: Set
|
||||
*
|
||||
* @param string $key Key
|
||||
* @param string $value Value
|
||||
* @return bool
|
||||
*/
|
||||
protected function set( $key, $value )
|
||||
{
|
||||
\IPS\Log::i( LOG_DEBUG )->setIpAddress( $_SERVER['REMOTE_ADDR'] )->write( "Set {$key} in Wincache", 'cache' );
|
||||
return (bool) wincache_ucache_set( \IPS\SUITE_UNIQUE_KEY . '_' . $key, $value );
|
||||
}
|
||||
|
||||
/**
|
||||
* Abstract Method: Exists?
|
||||
*
|
||||
* @param string $key Key
|
||||
* @return bool
|
||||
*/
|
||||
protected function exists( $key )
|
||||
{
|
||||
if( isset( $this->cache[ $key ] ) )
|
||||
{
|
||||
\IPS\Log::i( LOG_DEBUG )->setIpAddress( $_SERVER['REMOTE_ADDR'] )->write( "Check exists {$key} from Wincache (already loaded)", 'cache' );
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
\IPS\Log::i( LOG_DEBUG )->setIpAddress( $_SERVER['REMOTE_ADDR'] )->write( "Check exists {$key} from Wincache", 'cache' );
|
||||
return wincache_ucache_exists( \IPS\SUITE_UNIQUE_KEY . '_' . $key );
|
||||
}
|
||||
|
||||
/**
|
||||
* Abstract Method: Delete
|
||||
*
|
||||
* @param string $key Key
|
||||
* @return bool
|
||||
*/
|
||||
protected function delete( $key )
|
||||
{
|
||||
\IPS\Log::i( LOG_DEBUG )->setIpAddress( $_SERVER['REMOTE_ADDR'] )->write( "Delete {$key} from Wincache", 'cache' );
|
||||
|
||||
return (bool) wincache_ucache_delete( \IPS\SUITE_UNIQUE_KEY . '_' . $key );
|
||||
}
|
||||
|
||||
/**
|
||||
* Abstract Method: Clear All Caches
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function clearAll()
|
||||
{
|
||||
\IPS\Log::i( LOG_DEBUG )->setIpAddress( $_SERVER['REMOTE_ADDR'] )->write( "Flush all caches from Wincache", 'cache' );
|
||||
wincache_ucache_clear();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,108 @@
|
||||
<?php
|
||||
/**
|
||||
* @brief XCache Cache Class
|
||||
* @author <a href='http://www.invisionpower.com'>Invision Power Services, Inc.</a>
|
||||
* @copyright (c) 2001 - SVN_YYYY Invision Power Services, Inc.
|
||||
* @license http://www.invisionpower.com/legal/standards/
|
||||
* @package IPS Social Suite
|
||||
* @since 17 Sept 2013
|
||||
* @version SVN_VERSION_NUMBER
|
||||
*/
|
||||
|
||||
namespace IPS\Data\Cache;
|
||||
|
||||
/* To prevent PHP errors (extending class does not exist) revealing path */
|
||||
if ( !defined( '\IPS\SUITE_UNIQUE_KEY' ) )
|
||||
{
|
||||
header( ( isset( $_SERVER['SERVER_PROTOCOL'] ) ? $_SERVER['SERVER_PROTOCOL'] : 'HTTP/1.0' ) . ' 403 Forbidden' );
|
||||
exit;
|
||||
}
|
||||
|
||||
/**
|
||||
* XCache Storage Class
|
||||
*/
|
||||
class _Xcache extends \IPS\Data\Cache
|
||||
{
|
||||
/**
|
||||
* Server supports this method?
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public static function supported()
|
||||
{
|
||||
return function_exists('xcache_get');
|
||||
}
|
||||
|
||||
/**
|
||||
* Abstract Method: Get
|
||||
*
|
||||
* @param string $key Key
|
||||
* @return string Value from the _datastore
|
||||
*/
|
||||
protected function get( $key )
|
||||
{
|
||||
if( isset( $this->cache[ $key ] ) )
|
||||
{
|
||||
\IPS\Log::i( LOG_DEBUG )->setIpAddress( $_SERVER['REMOTE_ADDR'] )->write( "Get {$key} from Xcache (already loaded)", 'cache' );
|
||||
return $this->cache[ $key ];
|
||||
}
|
||||
|
||||
\IPS\Log::i( LOG_DEBUG )->setIpAddress( $_SERVER['REMOTE_ADDR'] )->write( "Get {$key} from Xcache", 'cache' );
|
||||
|
||||
$this->cache[ $key ] = xcache_get( \IPS\SUITE_UNIQUE_KEY . '_' . $key );
|
||||
return $this->cache[ $key ];
|
||||
}
|
||||
|
||||
/**
|
||||
* Abstract Method: Set
|
||||
*
|
||||
* @param string $key Key
|
||||
* @param string $value Value
|
||||
* @return bool
|
||||
*/
|
||||
protected function set( $key, $value )
|
||||
{
|
||||
\IPS\Log::i( LOG_DEBUG )->setIpAddress( $_SERVER['REMOTE_ADDR'] )->write( "Set {$key} in Xcache", 'cache' );
|
||||
return (bool) xcache_set( \IPS\SUITE_UNIQUE_KEY . '_' . $key, $value );
|
||||
}
|
||||
|
||||
/**
|
||||
* Abstract Method: Exists?
|
||||
*
|
||||
* @param string $key Key
|
||||
* @return bool
|
||||
*/
|
||||
protected function exists( $key )
|
||||
{
|
||||
if( isset( $this->cache[ $key ] ) )
|
||||
{
|
||||
\IPS\Log::i( LOG_DEBUG )->setIpAddress( $_SERVER['REMOTE_ADDR'] )->write( "Check exists {$key} from Xcache (already loaded)", 'cache' );
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
\IPS\Log::i( LOG_DEBUG )->setIpAddress( $_SERVER['REMOTE_ADDR'] )->write( "Check exists {$key} from Xcache", 'cache' );
|
||||
return xcache_isset( \IPS\SUITE_UNIQUE_KEY . '_' . $key );
|
||||
}
|
||||
|
||||
/**
|
||||
* Abstract Method: Delete
|
||||
*
|
||||
* @param string $key Key
|
||||
* @return bool
|
||||
*/
|
||||
protected function delete( $key )
|
||||
{
|
||||
\IPS\Log::i( LOG_DEBUG )->setIpAddress( $_SERVER['REMOTE_ADDR'] )->write( "Delete {$key} from Xcache", 'cache' );
|
||||
return (bool) xcache_unset( \IPS\SUITE_UNIQUE_KEY . '_' . $key );
|
||||
}
|
||||
|
||||
/**
|
||||
* Abstract Method: Clear All Caches
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function clearAll()
|
||||
{
|
||||
\IPS\Log::i( LOG_DEBUG )->setIpAddress( $_SERVER['REMOTE_ADDR'] )->write( "Flush all caches from Xcache (not implemented)", 'cache' );
|
||||
}
|
||||
}
|
||||
Whitespace-only changes.
Reference in new issue
Block a user