# wt-security/3.0.1/lib/Cache.php

WebTotem Security, version 3.0.1. 96 lines.

- Page: https://pluginprobe.com/plugins/wt-security/3.0.1/code/lib/Cache.php
- Raw: https://pluginprobe.com/plugins/wt-security/3.0.1/raw/lib/Cache.php
- Modified: 2026-05-15T03:23:06+00:00

Line numbers below start at 1. Link to a line or a range by appending a fragment to the
page URL, for example `https://pluginprobe.com/plugins/wt-security/3.0.1/code/lib/Cache.php#L10-L20`.

```php
<?php

if (!defined('WEBTOTEM_INIT') || WEBTOTEM_INIT !== true) {
	if (!headers_sent()) {
		header('HTTP/1.1 403 Forbidden');
	}
	die("Protected By WebTotem!");
}
/**
 * WebTotem Cache class for Wordpress.
 */
class WebTotemCache {

	const WTOTEM_CACHE_STORAGE_TIME = 5; // cache storage time in minutes
	/**
	 * Save multiple some data to cache.
	 *
	 * @param array $data
	 *   Array of data.
	 * @param string $host_id
	 *   The data belongs to this host.
	 * @param string $storage_time
	 *   Cache storage time in minutes.
	 *
	 * @return array
	 *   Returns TRUE after saving the data.
	 */
	public static function setData(array $data, $host_id, $storage_time = self::WTOTEM_CACHE_STORAGE_TIME) {

		$cache = json_decode(WebTotemOption::getOption('cache'), true) ?: [];
        $result = [];
		foreach ($data as $key => $value){
		    if(!empty($value) and !array_key_exists('errors', $value)){
                $expired = time() + ( $storage_time * 60 );
                $cache[$host_id][$key] = ['data' => $value, 'expired' => $expired];
                $result[$key] = true;
            } else {
		        $result[$key] = false;
            }
		}

		WebTotemOption::setOptions(['cache' => $cache]);

		return $result;
	}

	/**
	 * Get data from cache.
	 *
	 * @param string $key
	 *   Data key.
	 * @param string $host_id
	 *   The data belongs to this host.
	 *
	 * @return array
	 *   Returns saved data by key.
	 */
	public static function getdata($key, $host_id) {

		$cache = json_decode(WebTotemOption::getOption('cache'), true) ?: [];
		if(array_key_exists($host_id, $cache) and
		   array_key_exists($key, $cache[$host_id])
        ) { // and $cache[$host_id][$key]['expired'] > time()
			return [
				'data' => $cache[$host_id][$key]['data'],
				'remained' => $cache[$host_id][$key]['expired'] - time(),
			];
		} else {
			return [];
		}

	}

    /**
     * Delete data from cache.
     *
     * @param string $key
     *   Data key.
     * @param string $host_id
     *   The data belongs to this host.
     *
     * @return bool
     */
    public static function deleteData($key, $host_id) {

        $cache = json_decode(WebTotemOption::getOption('cache'), true) ?: [];

        unset($cache[$host_id][$key]);
        WebTotemOption::setOptions(['cache' => $cache]);

        return TRUE;

    }

}

```
