Version 4.3.0

This commit is contained in:
Neo committed 2025-12-19 05:47:12 -08:00
1 parent 96997ddd8e
commit fe1acf984a
1349 files changed
+116159 -67711

No files matched your search

+63 -35
View File
@@ -58,11 +58,6 @@ abstract class _Store extends AbstractData
*/
public $log = array();
/**
* @brief Flag to determine if we should check the validity of the cache via cacheKeys. We always want this to be on unless you have an exceptional reason to bypass the check.
*/
public $cacheCheck = TRUE;
/**
* Load mutiple
* Used so if it is known that several are going to be needed, they can all be loaded into memory at the same time
@@ -83,7 +78,7 @@ abstract class _Store extends AbstractData
public function test()
{
/* Set a test key */
$key = 'test_' . md5( uniqid() );
$key = 'test_' . md5( mt_rand() );
$this->$key = '1';
/* Now clear our internal cache to ensure the value isn't returned from there */
@@ -114,13 +109,13 @@ abstract class _Store extends AbstractData
try
{
/* If caching is enabled, and this isn't the special map of hashes... */
if ( ( ! \IPS\Data\Cache::i() instanceof \IPS\Data\Cache\None ) and $key !== 'cacheKeys' )
if ( $this->useCache( $key ) )
{
if ( $this->cacheCheck === false )
if ( \IPS\Data\Cache::i()->checkKeys() === false )
{
if ( isset( \IPS\Data\Cache::i()->$key ) and \IPS\Data\Cache::i()->$key !== NULL )
{
/* We accept it may be stale, so return it */
/* Cache engine always returns current content, so return it */
return \IPS\Data\Cache::i()->$key;
}
@@ -131,13 +126,13 @@ abstract class _Store extends AbstractData
{
/* It exists in the caching engine, and we know the hash of the correct value... */
$cacheKeys = ( isset( $this->cacheKeys ) and is_array( $this->cacheKeys ) ) ? $this->cacheKeys : array();
if ( isset( $cacheKeys[ $key ] ) and isset( \IPS\Data\Cache::i()->$key ) )
if ( array_key_exists( $key, $cacheKeys ) and isset( \IPS\Data\Cache::i()->$key ) )
{
/* Get it... */
$value = \IPS\Data\Cache::i()->$key;
/* But only use it if the hash matches */
if( \IPS\Login::compareHashes( $cacheKeys[ $key ], md5( json_encode( $value ) ) ) )
if( $cacheKeys[ $key ] == md5( json_encode( $value ) ) )
{
return $value;
}
@@ -156,15 +151,18 @@ abstract class _Store extends AbstractData
$value = parent::__get( $key );
/* If caching is enabled, and this isn't the special map of hashes... */
if ( ( ! \IPS\Data\Cache::i() instanceof \IPS\Data\Cache\None ) and $key !== 'cacheKeys' )
if ( $this->useCache( $key ) )
{
/* Set it in the caching engine... */
\IPS\Data\Cache::i()->$key = $value;
/* And set the hash in the cacheKeys hash map */
$cacheKeys = ( isset( $this->cacheKeys ) and is_array( $this->cacheKeys ) ) ? $this->cacheKeys : array();
$cacheKeys[ $key ] = md5( json_encode( $value ) );
$this->cacheKeys = $cacheKeys;
if ( \IPS\Data\Cache::i()->checkKeys() === true )
{
/* And set the hash in the cacheKeys hash map */
$cacheKeys = ( isset( $this->cacheKeys ) and is_array( $this->cacheKeys ) ) ? $this->cacheKeys : array();
$cacheKeys[ $key ] = md5( json_encode( $value ) );
$this->cacheKeys = $cacheKeys;
}
}
return $value;
@@ -184,21 +182,24 @@ abstract class _Store extends AbstractData
parent::__set( $key, $value );
/* If caching is enabled, and this isn't the special map of hashes... */
if ( ( ! \IPS\Data\Cache::i() instanceof \IPS\Data\Cache\None ) and $key !== 'cacheKeys' )
if ( $this->useCache( $key ) )
{
/* Then also set it in the cache... */
\IPS\Data\Cache::i()->$key = $value;
/* And set the hash in the cacheKeys hash map */
if ( ( isset( $this->cacheKeys ) and is_array( $this->cacheKeys ) ) )
if ( \IPS\Data\Cache::i()->checkKeys() === true )
{
$cacheKeys = is_array( $this->cacheKeys ) ? $this->cacheKeys : array();
$cacheKeys[ $key ] = md5( json_encode( $value ) );
$this->cacheKeys = $cacheKeys;
}
else
{
$this->cacheKeys = array( $key => md5( json_encode( $value ) ) );
if ( ( isset( $this->cacheKeys ) and is_array( $this->cacheKeys ) ) )
{
$cacheKeys = is_array( $this->cacheKeys ) ? $this->cacheKeys : array();
$cacheKeys[ $key ] = md5( json_encode( $value ) );
$this->cacheKeys = $cacheKeys;
}
else
{
$this->cacheKeys = array( $key => md5( json_encode( $value ) ) );
}
}
}
}
@@ -212,7 +213,7 @@ abstract class _Store extends AbstractData
public function __isset( $key )
{
/* If caching is enabled, and this isn't the special map of hashes, try to get it from the cache store... */
if ( ( ! \IPS\Data\Cache::i() instanceof \IPS\Data\Cache\None ) and $key !== 'cacheKeys' )
if ( $this->useCache( $key ) )
{
/* Does it exist in the caching engine? */
if ( isset( \IPS\Data\Cache::i()->$key ) )
@@ -220,15 +221,15 @@ abstract class _Store extends AbstractData
/* Get it... */
$value = \IPS\Data\Cache::i()->$key;
if ( $this->cacheCheck === false )
if ( \IPS\Data\Cache::i()->checkKeys() === false )
{
/* We accept it may be stale, so return it */
/* Cache engine always returns current content, so return it */
return TRUE;
}
/* Only use it if the hash matches */
$cacheKeys = ( isset( $this->cacheKeys ) and is_array( $this->cacheKeys ) ) ? $this->cacheKeys : array();
if ( isset( $cacheKeys[ $key ] ) and \IPS\Login::compareHashes( $cacheKeys[ $key ], md5( json_encode( $value ) ) ) )
if ( isset( $cacheKeys[ $key ] ) and $cacheKeys[ $key ] == md5( json_encode( $value ) ) )
{
return TRUE;
}
@@ -251,15 +252,42 @@ abstract class _Store extends AbstractData
parent::__unset( $key );
/* If caching is enabled, and this isn't the special map of hashes, remove it from the cache store... */
if ( ( ! \IPS\Data\Cache::i() instanceof \IPS\Data\Cache\None ) and $key !== 'cacheKeys' )
if ( $this->useCache( $key ) )
{
/* Remove it from the cache store... */
unset( \IPS\Data\Cache::i()->$key );
/* And from the special map of hashes */
$cacheKeys = is_array( $this->cacheKeys ) ? $this->cacheKeys : array();
unset( $cacheKeys[ $key ] );
$this->cacheKeys = $cacheKeys;
if ( \IPS\Data\Cache::i()->checkKeys() === true )
{
/* And from the special map of hashes */
try
{
$cacheKeys = is_array( $this->cacheKeys ) ? $this->cacheKeys : array();
}
/* If the cache doesn't exist we shouldn't error out with an uncaught OutOfRangeException */
catch( \OutOfRangeException $e )
{
$cacheKeys = array();
}
if( isset( $cacheKeys[ $key ] ) )
{
unset( $cacheKeys[ $key ] );
}
$this->cacheKeys = $cacheKeys;
}
}
}
/**
* Check the cache for this key?
*
* @param string $key The store key
* @return boolean
*/
protected function useCache( $key )
{
return ( \IPS\CACHE_METHOD != \IPS\STORE_METHOD and ( ! \IPS\Data\Cache::i() instanceof \IPS\Data\Cache\None ) and $key !== 'cacheKeys' );
}
}