BomAle Posted March 5, 2018 Posted March 5, 2018 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
teraßyte Posted March 6, 2018 Posted March 6, 2018 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...
BomAle Posted March 6, 2018 Author Posted March 6, 2018 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.
Stuart Silvester Posted March 6, 2018 Posted March 6, 2018 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
BomAle Posted March 6, 2018 Author Posted March 6, 2018 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 ?
Daniel F Posted March 16, 2018 Posted March 16, 2018 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.
BomAle Posted March 16, 2018 Author Posted March 16, 2018 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 ?
Recommended Posts
Archived
This topic is now archived and is closed to further replies.