PHP 8.1.33
Preview: CCacheHttpSession.php Size: 3.20 KB
/home/jambtst2015/www/framework/web/CCacheHttpSession.php

<?php
/**
 * CCacheHttpSession class
 *
 * @author Qiang Xue <qiang.xue@gmail.com>
 * @link http://www.yiiframework.com/
 * @copyright 2008-2013 Yii Software LLC
 * @license http://www.yiiframework.com/license/
 */


/**
 * CCacheHttpSession implements a session component using cache as storage medium.
 *
 * The cache being used can be any cache application component implementing {@link ICache} interface.
 * The ID of the cache application component is specified via {@link cacheID}, which defaults to 'cache'.
 *
 * Beware, by definition cache storage are volatile, which means the data stored on them
 * may be swapped out and get lost. Therefore, you must make sure the cache used by this component
 * is NOT volatile. If you want to use {@link CDbCache} as storage medium, use {@link CDbHttpSession}
 * is a better choice.
 *
 * @property boolean $useCustomStorage Whether to use custom storage.
 *
 * @author Qiang Xue <qiang.xue@gmail.com>
 * @package system.web
 * @since 1.0
 */
class CCacheHttpSession extends CHttpSession
{
	/**
	 * Prefix to the keys for storing cached data
	 */
	const CACHE_KEY_PREFIX='Yii.CCacheHttpSession.';
	/**
	 * @var string the ID of the cache application component. Defaults to 'cache' (the primary cache application component.)
	 */
	public $cacheID='cache';

	/**
	 * @var ICache the cache component
	 */
	private $_cache;

	/**
	 * Initializes the application component.
	 * This method overrides the parent implementation by checking if cache is available.
	 */
	public function init()
	{
		$this->_cache=Yii::app()->getComponent($this->cacheID);
		if(!($this->_cache instanceof ICache))
			throw new CException(Yii::t('yii','CCacheHttpSession.cacheID is invalid. Please make sure "{id}" refers to a valid cache application component.',
				array('{id}'=>$this->cacheID)));
		parent::init();
	}

	/**
	 * Returns a value indicating whether to use custom session storage.
	 * This method overrides the parent implementation and always returns true.
	 * @return boolean whether to use custom storage.
	 */
	public function getUseCustomStorage()
	{
		return true;
	}

	/**
	 * Session read handler.
	 * Do not call this method directly.
	 * @param string $id session ID
	 * @return string the session data
	 */
	public function readSession($id)
	{
		$data=$this->_cache->get($this->calculateKey($id));
		return $data===false?'':$data;
	}

	/**
	 * Session write handler.
	 * Do not call this method directly.
	 * @param string $id session ID
	 * @param string $data session data
	 * @return boolean whether session write is successful
	 */
	public function writeSession($id,$data)
	{
		return $this->_cache->set($this->calculateKey($id),$data,$this->getTimeout());
	}

	/**
	 * Session destroy handler.
	 * Do not call this method directly.
	 * @param string $id session ID
	 * @return boolean whether session is destroyed successfully
	 */
	public function destroySession($id)
	{
	    return $this->_cache->delete($this->calculateKey($id));
	}

	/**
	 * Generates a unique key used for storing session data in cache.
	 * @param string $id session variable name
	 * @return string a safe cache key associated with the session variable name
	 */
	protected function calculateKey($id)
	{
	    return self::CACHE_KEY_PREFIX.$id;
	}
}

Directory Contents

Dirs: 9 × Files: 28

Name Size Perms Modified Actions
actions DIR
- drwxr-xr-x 2025-10-08 19:22:44
Edit Download
auth DIR
- drwxr-xr-x 2025-10-08 19:45:04
Edit Download
filters DIR
- drwxr-xr-x 2025-10-11 10:02:11
Edit Download
form DIR
- drwxr-xr-x 2025-10-09 05:45:59
Edit Download
helpers DIR
- drwxr-xr-x 2025-10-11 04:35:21
Edit Download
js DIR
- drwxr-xr-x 2025-10-15 09:54:12
Edit Download
renderers DIR
- drwxr-xr-x 2025-10-11 01:32:19
Edit Download
services DIR
- drwxr-xr-x 2025-10-12 12:01:04
Edit Download
widgets DIR
- drwxr-xr-x 2025-10-08 17:42:55
Edit Download
6.45 KB lrw-r--r-- 2024-11-22 17:53:15
Edit Download
5.93 KB lrw-r--r-- 2024-11-22 17:53:15
Edit Download
13.46 KB lrw-r--r-- 2024-11-22 17:53:15
Edit Download
9.99 KB lrw-r--r-- 2024-11-22 17:53:15
Edit Download
3.20 KB lrw-r--r-- 2024-11-22 17:53:15
Edit Download
27.88 KB lrw-r--r-- 2024-11-22 17:53:15
Edit Download
46.39 KB lrw-r--r-- 2024-11-22 17:53:15
Edit Download
7.01 KB lrw-r--r-- 2024-11-22 17:53:15
Edit Download
4.21 KB lrw-r--r-- 2024-11-22 17:53:15
Edit Download
8.63 KB lrw-r--r-- 2024-11-22 17:53:15
Edit Download
1.45 KB lrw-r--r-- 2024-11-22 17:53:15
Edit Download
2.12 KB lrw-r--r-- 2024-11-22 17:53:15
Edit Download
2.67 KB lrw-r--r-- 2024-11-22 17:53:15
Edit Download
47.44 KB lrw-r--r-- 2024-11-22 17:53:15
Edit Download
16.31 KB lrw-r--r-- 2024-11-22 17:53:15
Edit Download
1.87 KB lrw-r--r-- 2024-11-22 17:53:15
Edit Download
883 B lrw-r--r-- 2024-11-22 17:53:15
Edit Download
7.14 KB lrw-r--r-- 2024-11-22 17:53:15
Edit Download
17.31 KB lrw-r--r-- 2024-11-22 17:53:15
Edit Download
4.18 KB lrw-r--r-- 2024-11-22 17:53:15
Edit Download
3.58 KB lrw-r--r-- 2024-11-22 17:53:15
Edit Download
3.68 KB lrw-r--r-- 2024-11-22 17:53:15
Edit Download
9.13 KB lrw-r--r-- 2024-11-22 17:53:15
Edit Download
27.42 KB lrw-r--r-- 2024-11-22 17:53:15
Edit Download
16.96 KB lrw-r--r-- 2024-11-22 17:53:15
Edit Download
6.53 KB lrw-r--r-- 2024-11-22 17:53:15
Edit Download
7.38 KB lrw-r--r-- 2024-11-22 17:53:15
Edit Download
192.84 KB lrw-r--r-- 2025-11-04 15:12:28
Edit Download

If ZipArchive is unavailable, a .tar will be created (no compression).