# optin/trunk/includes/utils/class-cache.php

WowOptin: Next-Gen Popup Maker – Create Stunning Popups and Optins for Lead Generation, version trunk. 51 lines.

- Page: https://pluginprobe.com/plugins/optin/trunk/code/includes/utils/class-cache.php
- Raw: https://pluginprobe.com/plugins/optin/trunk/raw/includes/utils/class-cache.php
- Modified: 2026-05-06T10:46:56+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/optin/trunk/code/includes/utils/class-cache.php#L10-L20`.

```php
<?php // phpcs:ignore

namespace OPTN\Includes\Utils;

use OPTN\Includes\Traits\Singleton;

defined( 'ABSPATH' ) || exit;


/**
 * Cache class
 */
class Cache {
	use Singleton;

	/**
	 * Gets value from cache by key
	 *
	 * @param string $key key of the value.
	 * @param mixed  $default_value default value if value in not in cache.
	 * @return mixed
	 */
	public static function get( $key, $default_value = null ) {
		$res = get_transient( $key );
		return $res ? $res : $default_value;
	}

	/**
	 * Deletes value from cache by kea
	 *
	 * @param string $key key of the value.
	 * @return bool
	 */
	public static function remove( $key ) {
		return delete_transient( $key );
	}

	/**
	 * Sets a value in cache
	 *
	 * @param string   $key key of the value.
	 * @param mixed    $value value to store in cache.
	 * @param int|null $days cache expiration in days.
	 * @return bool
	 */
	public static function set( $key, $value, $days = null ) {
		$d = empty( $days ) ? OPTN_CACHE_DAY : $days;
		return set_transient( $key, $value, DAY_IN_SECONDS * $d );
	}
}

```
