Jump to content

Improve exclusion on clearAll method Store


BomAle

Recommended Posts

Posted

Currently clearAll not support fine exclusion of more file, is possible to improve it for each store method? (like with a custom callback/regex/array)

system/Data/Store/FileSystem.php

 

	/**
	 * Abstract Method: Clear All Caches
	 *
	 * @return	void
	 */
	public function clearAll( $exclude=NULL )
	{
		foreach ( new \DirectoryIterator( $this->_path ) as $file )
		{			
			if ( !$file->isDot() and ( mb_substr( $file, -9 ) === '.ipsstore' or ( mb_substr( $file, -4 ) === '.php' and $file != $exclude . '.php' ) ) )
			{
				@unlink( $this->_path . '/' . $file );
			}
		}

		foreach( static::$cache as $key => $value )
		{
			if( $exclude === NULL OR $key != $exclude )
			{
				unset( static::$cache[ $key ] );
			}
		}

		/* Clear zend opcache if enabled - we call reset here since we're wiping multiple files
			and since this gets called as part of a general 'rebuild everything', a reset is 
			probably a good idea anyway */
		if ( function_exists( 'opcache_reset' ) )
		{
			@opcache_reset();
		}
	}

system/Data/Store/Database.php

 

	/**
	 * Abstract Method: Clear All Caches
	 *
	 * @return	void
	 */
	public function clearAll( $exclude=NULL )
	{
		$where = array();
		if( $exclude !== NULL )
		{
			$where[] = array( 'store_key != ?', $exclude );
		}
		\IPS\Db::i()->delete( 'core_store', $where );

		foreach( static::$cache as $key => $value )
		{
			if( $exclude === NULL OR $key != $exclude )
			{
				unset( static::$cache[ $key ] );
			}
		}
	}

EDIT: temporary fix with plugin Exclude clearAll for Store.xml

Posted

Well... the method name is "clearAll?

That said, you should be able to clear specific caches by using unset() without needing to call clearAll(). Or are you trying to do something else? I'm not sure...

Posted

Thanks terabyte, when the system use it, during update/install/uninstall app or plugin, my stored value is removed and I would it is not removed otherwise are triggered functions that should not be performed.

my code currently is

if(!isset(\ips\data\store::i()->$key))
{
	//send to telegram notification
	//update ips\data\store::i()->$key = $items
}
elseif(/*$diff = diff from request and stored value*/)
{
// send to telegram notification for $diff
// $key = array_slice(array_merge $diff and $key stored, 0, 10)
}

  I am not on pc for show full code, I use a external php file.

Posted
1 hour ago, BomAle said:

Thanks terabyte, when the system use it, during update/install/uninstall app or plugin, my stored value is removed and I would it is not removed otherwise are triggered functions that should not be performed.

my code currently is


if(!isset(\ips\data\store::i()->$key))
{
	//send to telegram notification
	//update ips\data\store::i()->$key = $items
}
elseif(/*$diff = diff from request and stored value*/)
{
// send to telegram notification for $diff
// $key = array_slice(array_merge $diff and $key stored, 0, 10)
}

  I am not on pc for show full code, I use a external php file.

You shouldn't be storing any value in the datastore that you want to persist. It is non-persistent storage.

Your code must also be able to handle the fact that it may not be there and generate the stored value on demand.

See 

 

Posted
1 hour ago, Stuart Silvester said:

It is non-persistent storage. 

I would suggest you make it persistent, or permise developer handle when it has been cleared. But this is not the place for suggestions ?

  • 2 weeks later...
Posted
On 6.3.2018 at 10:16 PM, BomAle said:

I would suggest you make it persistent, or permise developer handle when it has been cleared. But this is not the place for suggestions ?

No, the datastore is really only for temporary usage. You should NEVER store persistent data in the datastore.
We've mentioned this in several topics and since I'm doing code reviews of the MP submissions I'm also highlighting this to the contributors.

Depending on the data you want to store, you should either create an own table to save the data and then you can cache them in the datastore or you could also use the IPS\Settings implantation to save them, but you should really never use the datastore for this.
It's really only a temporary cache, which is truncated by the system.

Posted

I solved change:

if (!isset(\ips\data\store::i()->$key))

into

if (\IPS\Request::i()->do == "install" and !isset(\ips\data\store::i()->$key)) 

this way there are not issues... thanks for each response ?

Archived

This topic is now archived and is closed to further replies.

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...