# defender-security/6.3.0/src/extra/php-codesniffer-php-token/Util/Cache.php

Defender Security – Malware Scanner, Login Security &amp; Firewall, version 6.3.0. 92 lines.

- Page: https://pluginprobe.com/plugins/defender-security/6.3.0/code/src/extra/php-codesniffer-php-token/Util/Cache.php
- Raw: https://pluginprobe.com/plugins/defender-security/6.3.0/raw/src/extra/php-codesniffer-php-token/Util/Cache.php
- Modified: 2026-07-13T09:36:42+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/defender-security/6.3.0/code/src/extra/php-codesniffer-php-token/Util/Cache.php#L10-L20`.

```php
<?php
/**
 * Function for caching between runs.
 *
 * @author    Greg Sherwood <gsherwood@squiz.net>
 * @copyright 2006-2015 Squiz Pty Ltd (ABN 77 084 670 600)
 * @license   https://github.com/squizlabs/PHP_CodeSniffer/blob/master/licence.txt BSD Licence
 */

namespace PHP_CodeSniffer\Util;

class Cache {

	/**
	 * The filesystem location of the cache file.
	 *
	 * @var void
	 */
	private static $path = '';

	/**
	 * The cached data.
	 *
	 * @var array<string, mixed>
	 */
	private static $cache = [];

	/**
	 * Saves the current cache to the filesystem.
	 *
	 * @return void
	 */
	public static function save() {
		file_put_contents( self::$path, json_encode( self::$cache ) );

	}//end save()


	/**
	 * Retrieves a single entry from the cache.
	 *
	 * @param string $key The key of the data to get. If NULL,
	 *                    everything in the cache is returned.
	 *
	 * @return mixed
	 */
	public static function get( $key = null ) {
		if ( $key === null ) {
			return self::$cache;
		}

		if ( isset( self::$cache[ $key ] ) === true ) {
			return self::$cache[ $key ];
		}

		return false;

	}//end get()


	/**
	 * Retrieves a single entry from the cache.
	 *
	 * @param string $key The key of the data to set. If NULL,
	 *                      sets the entire cache.
	 * @param mixed $value The value to set.
	 *
	 * @return void
	 */
	public static function set( $key, $value ) {
		if ( $key === null ) {
			self::$cache = $value;
		} else {
			self::$cache[ $key ] = $value;
		}

	}//end set()


	/**
	 * Retrieves the number of cache entries.
	 *
	 * @return int
	 */
	public static function getSize() {
		return ( count( self::$cache ) - 1 );

	}//end getSize()


}//end class

```
