/**
  * Unset a Page from the (Persistent) Cache.
  *
  * @param 	STRING 		$storage_namespace		:: the cache storage namespace, used to group keys
  * @param 	STRING 		$unique_key				:: the unique cache key
  *
  * @return 	BOOL								:: TRUE if the PersistentCache is active and value was unset ; FALSE in the rest of the cases
  */
 public final function PageUnsetFromCache($storage_namespace, $unique_key)
 {
     //--
     return SmartPersistentCache::unsetKey((string) $storage_namespace, (string) $unique_key);
     //--
 }
    public static function test_redisserver()
    {
        global $configs;
        //--
        if (SMART_FRAMEWORK_TESTUNIT_ALLOW_REDIS_TESTS !== true) {
            return SmartComponents::operation_notice('Test Unit for Redis Server is DISABLED ...');
        }
        //end if
        //--
        //--
        if (SmartPersistentCache::isActive()) {
            //--
            $redis_big_content = self::pack_test_archive();
            // CREATE THE Test Archive (time not counted)
            //--
            $redis_test_key = 'redis-test-key_' . Smart::uuid_10_num() . '-' . Smart::uuid_36() . '-' . Smart::uuid_45();
            $redis_test_value = array('unicode-test' => '"Unicode78źź:ăĂîÎâÂșȘțȚşŞţŢグッド', 'big-key-test' => (string) $redis_big_content, 'random-key' => Smart::uuid_10_str() . '.' . Smart::random_number(1000, 9999));
            $redis_test_checkum = sha1(implode("\n", (array) $redis_test_value));
            $redis_test_arch_content = SmartUtils::cache_variable_archive($redis_test_value);
            $redis_test_arch_checksum = sha1($redis_test_arch_content);
            //--
            $tests = array();
            $tests[] = '##### Redis / TESTS (Persistent Cache) with a Variable Key-Size of ' . SmartUtils::pretty_print_bytes(strlen($redis_test_arch_content), 2) . ' : #####';
            //--
            $err = '';
            //--
            if ((string) $err == '') {
                $tests[] = 'Building a Test Archive file for Redis Tests (time not counted)';
                // archive was previous created, only test here
                if ((string) $redis_big_content == '') {
                    $err = 'Failed to build the Test Archive file for the Redis Test (see the error log for more details) ...';
                }
                //end if
            }
            //end if
            //--
            $time = microtime(true);
            $tests[] = '++ START Counter ...';
            //--
            if ((string) $err == '') {
                $tests[] = 'Building the Cache Archive';
                if ((string) $redis_test_arch_content == '') {
                    $err = 'Failed to build the Cache Variable(s) Archive file for the Redis Test (see the error log for more details) ...';
                }
                //end if
            }
            //end if
            //--
            if ((string) $err == '') {
                $tests[] = 'Set a short Redis Key (auto-expire in 3 seconds)';
                $redis_set_key = SmartPersistentCache::setKey('redis-server-tests', $redis_test_key, (string) $redis_test_value['unicode-test'], 3);
                if ($redis_set_key !== true) {
                    $err = 'Redis SetKey (short) returned a non-true result: ' . "\n" . $redis_test_key;
                }
                //end if
                if ((string) $err == '') {
                    $tests[] = 'Wait 5 seconds for Redis Key to expire, then check again if exists (time not counted)';
                    sleep(5);
                    // wait the Redis Key to Expire
                    $time = (double) $time + 5;
                    // ignore those 5 seconds (waiting time) to fix counter
                    $tests[] = '-- FIX Counter (substract the 5 seconds, waiting time) ...';
                    if (SmartPersistentCache::keyExists('redis-server-tests', $redis_test_key)) {
                        $err = 'Redis (short) Key does still exists (but should be expired after 5 seconds) and is not: ' . "\n" . $redis_test_key;
                    }
                    //end if
                }
                //end if
            }
            //end if
            //--
            if ((string) $err == '') {
                $tests[] = 'Set a long Redis Key (will not expire)';
                $redis_set_key = SmartPersistentCache::setKey('redis-server-tests', $redis_test_key, $redis_test_arch_content);
                if ($redis_set_key !== true) {
                    $err = 'Redis SetKey (long) returned a non-true result: ' . "\n" . $redis_test_key;
                }
                //end if
            }
            //end if
            //--
            if ((string) $err == '') {
                $tests[] = 'Check if Redis Key exists (after set)';
                if (!SmartPersistentCache::keyExists('redis-server-tests', $redis_test_key)) {
                    $err = 'Redis Key does not exists: ' . "\n" . $redis_test_key;
                }
                //end if
            }
            //end if
            //--
            if ((string) $err == '') {
                $tests[] = 'Get Redis Key';
                $redis_cached_value = SmartUtils::cache_variable_unarchive(SmartPersistentCache::getKey('redis-server-tests', $redis_test_key));
                if (Smart::array_size($redis_cached_value) > 0) {
                    $tests[] = 'Check if Redis Key is valid (array-keys)';
                    if ((string) $redis_cached_value['unicode-test'] != '' and (string) $redis_cached_value['big-key-test'] != '') {
                        $tests[] = 'Check if Redis Key is valid (checksum)';
                        if ((string) sha1(implode("\n", (array) $redis_cached_value)) == (string) $redis_test_checkum) {
                            if ($redis_test_value === $redis_cached_value) {
                                $tests[] = 'Unset Redis Key';
                                $redis_unset_key = SmartPersistentCache::unsetKey('redis-server-tests', $redis_test_key);
                                if ($redis_unset_key === true) {
                                    $tests[] = 'Check if Redis Key exists (after unset)';
                                    if (SmartPersistentCache::keyExists('redis-server-tests', $redis_test_key)) {
                                        $err = 'Redis Key does exists (after unset) and should not: ' . "\n" . $redis_test_key;
                                    } else {
                                        // OK
                                    }
                                    //end if
                                } else {
                                    $err = 'Redis UnSetKey returned a non-true result: ' . "\n" . $redis_test_key;
                                }
                                //end if else
                            } else {
                                $err = 'Redis Cached Value is broken: comparing stored value with original value failed on key: ' . "\n" . $redis_test_key;
                            }
                            //end if else
                        } else {
                            $err = 'Redis Cached Value is broken: checksum failed on key: ' . "\n" . $redis_test_key;
                        }
                        //end if else
                    } else {
                        $err = 'Redis Cached Value is broken: array-key is missing after Cache-Variable-Unarchive on key: ' . "\n" . $redis_test_key;
                    }
                    //end if
                } else {
                    $err = 'Redis Cached Value is broken: non-array value was returned after Cache-Variable-Unarchive on key: ' . "\n" . $redis_test_key;
                }
                //end if
            }
            //end if
            //--
            $title = 'SmartFramework Redis Server Tests: DONE ...';
            //--
            $time = 'TOTAL TIME (Except building the test archive) was: ' . (microtime(true) - $time);
            // substract the 3 seconds waiting time for Redis Key to expire
            //--
            $end_tests = '##### END TESTS ... ' . $time . ' sec. #####';
            //--
            if ((string) $err == '') {
                $img_sign = 'lib/core/img/sign_info.png';
                $img_check = 'lib/core/img/q_completed.png';
                $text_main = Smart::escape_js('<span style="color:#83B953;">Good ... Perfect &nbsp;&nbsp;&nbsp; :: &nbsp;&nbsp;&nbsp; グッド ... パーフェクト</span>');
                $text_info = Smart::escape_js('<h2><span style="color:#83B953;">All</span> the SmartFramework Redis Server Operations <span style="color:#83B953;">Tests PASSED on PHP</span><hr></h2><span style="font-size:14px;">' . Smart::nl_2_br(Smart::escape_html(implode("\n" . '* ', $tests) . "\n" . $end_tests)) . '</span>');
            } else {
                $img_sign = 'lib/core/img/sign_error.png';
                $img_check = 'lib/core/img/q_warning.png';
                $text_main = Smart::escape_js('<span style="color:#FF5500;">An ERROR occured ... &nbsp;&nbsp;&nbsp; :: &nbsp;&nbsp;&nbsp; エラーが発生しました ...</span>');
                $text_info = Smart::escape_js('<h2><span style="color:#FF5500;">A test FAILED</span> when testing Redis Server Operations.<span style="color:#FF5500;"><hr>FAILED Test Details</span>:</h2><br><span style="font-size:14px;"><pre>' . Smart::escape_html($err) . '</pre></span>');
            }
            //end if else
            //--
        } else {
            //--
            $title = 'SmartFramework Redis Server Tests - Redis Server was NOT SET ...';
            //--
            $img_sign = 'lib/core/img/sign_info.png';
            $img_check = 'lib/core/img/q_warning.png';
            $text_main = Smart::escape_js('<span style="color:#778899;">No Redis Server Tests performed ...</span>');
            $text_info = '<h2>The current configuration have not set the Redis Server ...</h2>';
            //--
        }
        //end if
        //--
        //--
        $html = <<<HTML
<h1>{$title}</h1>
<script type="text/javascript">
\tSmartJS_BrowserUtils.alert_Dialog(
\t\t'<img src="{$img_sign}" align="right"><h1>{$text_main}</h1><hr><span style="color:#333333;"><img src="{$img_check}" align="right">{$text_info}<br>',
\t\t'',
\t\t'Redis Server Test Suite for SmartFramework: PHP',
\t\t'725',
\t\t'480'
\t);
</script>
HTML;
        //--
        //--
        return $html;
        //--
    }
 private static function getFromPersistentCache($the_cache_key, $version_translations)
 {
     //--
     $arr = array();
     //--
     if (SmartPersistentCache::isActive() and SmartPersistentCache::isMemoryBased()) {
         //-- if not set translations versions, set them to internal cache :: this will be executed just once per session and is necessary to keep sync between Persistent Cache Translations and Real Translation Sources
         if ((string) $version_translations == '') {
             Smart::log_warning('Empty Version for Text Translations ... It is needed for store them in the Persistent Cache !');
         }
         //end if
         //-- check if persistent cache texts are outdated
         $check_version = true;
         if ((string) self::$cache['#VERSION#'] != '') {
             $check_version = false;
         } elseif ((string) $version_translations === (string) SmartPersistentCache::getKey('smart-regional-texts', 'version')) {
             $check_version = false;
         }
         //end if else
         if ($check_version !== false) {
             //-- cleanup the outdated text keys from persistent cache
             SmartPersistentCache::unsetKey('smart-regional-texts', '*');
             //-- re-register in persistent cache the Date and Version (after cleanup)
             if (!SmartPersistentCache::keyExists('smart-regional-texts', 'version')) {
                 if (!SmartPersistentCache::keyExists('smart-regional-texts', 'date')) {
                     if (SmartPersistentCache::setKey('smart-regional-texts', 'date', 'Cached on: ' . date('Y-m-d H:i:s O'))) {
                         SmartPersistentCache::setKey('smart-regional-texts', 'version', (string) $version_translations);
                     }
                     //end if
                 }
                 //end if
             }
             //end if
             //--
         } else {
             // text keys in persistent cache appear to be latest version, try to get it
             //--
             self::$cache['#VERSION#'] = (string) $version_translations;
             //--
             $rdata = SmartPersistentCache::getKey('smart-regional-texts', (string) $the_cache_key);
             if ($rdata) {
                 // here evaluates if non-false
                 $rdata = Smart::unseryalize((string) $rdata);
             }
             //end if
             if (Smart::array_size($rdata) > 0) {
                 $arr = (array) $rdata;
             }
             //end if
             $rdata = '';
             // clear
             //--
         }
         //end if
         //--
     }
     //end if
     //--
     return (array) $arr;
     //--
 }