Version 4.1.2

This commit is contained in:
Neo committed 2025-12-19 05:32:19 -08:00
1 parent 3ba79295ee
commit 28bd025b35
1131 files changed
+63658 -20579

No files matched your search

+57 -48
View File
@@ -79,43 +79,45 @@ abstract class _Store extends AbstractData
*/
public function __get( $key )
{
if( \IPS\CACHE_METHOD !== 'None' )
{
if( isset( $this->cacheKeys ) )
{
$cacheKeys = $this->cacheKeys;
if( !is_array( $cacheKeys ) )
{
$cacheKeys = array();
}
}
else
{
$cacheKeys = array();
}
}
/* Try to get it from the cache store... */
try
{
if ( \IPS\CACHE_METHOD !== 'None' and $key !== 'cacheKeys' and isset( $cacheKeys[ $key ] ) and isset( \IPS\Data\Cache::i()->$key ) )
{
$value = \IPS\Data\Cache::i()->$key;
if ( $cacheKeys[ $key ] === md5( json_encode( $value ) ) )
{
return $value;
}
}
throw new \OutOfRangeException;
}
catch ( \OutOfRangeException $e )
{
$value = parent::__get( $key );
/* If caching is enabled, and this isn't the special map of hashes... */
if ( \IPS\CACHE_METHOD !== 'None' and $key !== 'cacheKeys' )
{
/* And 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 ) )
{
/* Get it... */
$value = \IPS\Data\Cache::i()->$key;
/* But only use it if the hash matches */
if ( $cacheKeys[ $key ] === md5( json_encode( $value ) ) )
{
return $value;
}
}
}
/* Still here? throw an exception so we get it from the data storage engine */
throw new \OutOfRangeException;
}
/* If we couldn't get it from the cache engine, get it from the data storage engine */
catch ( \OutOfRangeException $e )
{
/* Actually get it... */
$value = parent::__get( $key );
/* If caching is enabled, and this isn't the special map of hashes... */
if ( \IPS\CACHE_METHOD !== 'None' and $key !== 'cacheKeys' )
{
/* 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;
}
@@ -133,13 +135,17 @@ abstract class _Store extends AbstractData
*/
public function __set( $key, $value )
{
/* Actually set it in the data storage engine */
parent::__set( $key, $value );
/* If caching is enabled, and this isn't the special map of hashes... */
if ( \IPS\CACHE_METHOD !== 'None' and $key !== 'cacheKeys' )
{
/* Then also set it in the cache... */
\IPS\Data\Cache::i()->$key = $value;
if ( isset( $this->cacheKeys ) )
/* And set the hash in the cacheKeys hash map */
if ( ( isset( $this->cacheKeys ) and is_array( $this->cacheKeys ) ) )
{
$cacheKeys = is_array( $this->cacheKeys ) ? $this->cacheKeys : array();
$cacheKeys[ $key ] = md5( json_encode( $value ) );
@@ -160,19 +166,25 @@ abstract class _Store extends AbstractData
*/
public function __isset( $key )
{
if ( \IPS\CACHE_METHOD !== 'None' and $key !== 'cacheKeys' and isset( $this->cacheKeys ) and isset( $this->cacheKeys[ $key ] ) and isset( \IPS\Data\Cache::i()->$key ) )
/* If caching is enabled, and this isn't the special map of hashes, try to get it from the cache store... */
if ( \IPS\CACHE_METHOD !== 'None' and $key !== 'cacheKeys' )
{
try
/* Does it exist in the caching engine? */
if ( isset( \IPS\Data\Cache::i()->$key ) )
{
/* Get it... */
$value = \IPS\Data\Cache::i()->$key;
if ( $this->cacheKeys[ $key ] === md5( json_encode( $value ) ) )
/* But only use it if the hash matches */
$cacheKeys = ( isset( $this->cacheKeys ) and is_array( $this->cacheKeys ) ) ? $this->cacheKeys : array();
if ( isset( $cacheKeys[ $key ] ) and $cacheKeys[ $key ] === md5( json_encode( $value ) ) )
{
return TRUE;
}
}
catch ( \OutOfRangeException $e ) { }
}
}
}
/* If we're still here, check the data storage engine... */
return parent::__isset( $key );
}
@@ -184,22 +196,19 @@ abstract class _Store extends AbstractData
*/
public function __unset( $key )
{
/* Unset it in the data storage engine */
parent::__unset( $key );
/* If caching is enabled, and this isn't the special map of hashes, remove it from the cache store... */
if ( \IPS\CACHE_METHOD !== 'None' and $key !== 'cacheKeys' )
{
/* Remove it from the cache store... */
unset( \IPS\Data\Cache::i()->$key );
if ( isset( $this->cacheKeys ) )
{
$cacheKeys = is_array( $this->cacheKeys ) ? $this->cacheKeys : array();
if( isset( $cacheKeys[ $key ] ) )
{
unset( $cacheKeys[ $key ] );
$this->cacheKeys = $cacheKeys;
}
}
/* And from the special map of hashes */
$cacheKeys = is_array( $this->cacheKeys ) ? $this->cacheKeys : array();
unset( $cacheKeys[ $key ] );
$this->cacheKeys = $cacheKeys;
}
}
}