المساعد الشخصي الرقمي

مشاهدة النسخة كاملة : كلاس افضل كلاس للكاش في الدنيا cache



mostafaxman
03-17-2009, 10:41 AM
بسم الله الرحمن الرحيم



يا تري حد فيكم جرب مكتبة الAPC في الPHP لأن لو في حد جرب المكتبة دي هايلاحظ انها افضل مكتبة للكاش علي الاطلاق

المهم انا كنت استخدمت المكتبة دي في اني اعمل الكلاس ده هوه زي ما قلت للكاش

غير كده ....
انتم لما تشوفوا الكلاس ده لازم تباركوا لي
لأني اول مرة استخدم الinterface في الكلاسات
كنت جربتها قبل كده بس مش في كلاس المهم جربوه و قولوا ايه رأيكم

الكلاس :




<?php
/*
* @author: Ahmed H AboElnasser <support@egysolutions.net>
* @license MIT
* @since: Class available since EgySolutions Framework 0.1.1 Beta
* @link: http://www.egysolutions.net
* Requires: PHP 5.1.4+
* @package: EgySolutions Framework
* @category: core
* @subpackage: cache
*/

/**
* Interfaces
* for all Cache Classes to implement
*/
interface EgysolutionsCacheInterface
{
function fetch($key);
function store($key, $data, $time_to_live);
function delete($key);
}

/**
* Cache Handler
*
*/
class cache
{
function __construct()
{
// Check if APC extension is loaded
if( !defined('GID_EXTENSION_LOADED_APC') )
define( 'GID_EXTENSION_LOADED_APC', extension_loaded('apc') );

// only get the data off the **** file if we can't get it from
// APC i.e. from memory
if( !(GID_EXTENSION_LOADED_APC && ($this->_keywords=apc_fetch('highlighter_keywords'))) );


// if APC is loaded, store the data in memory
if( GID_EXTENSION_LOADED_APC )
apc_store( 'highlighter_keywords', $this->_keywords );
}
}

/**
* APC = Alternative PHP Cache
*/
class Egysolutions_cache_apc implements EgysolutionsCacheInterface
{
// apc_fetch
function fetch($key)
{
return apc_fetch($key);
}
// apc_store
function store($key,$data,$time_to_live)
{
return apc_store($key,$data,$time_to_live);
}

// apc_delete
function delete($key)
{
return apc_delete($key);
}
}

/**
* memcached
*/
class Egysolutions_cache_memcached implements EgysolutionsCacheInterface
{
$cache = NULL;

function __construct()
{
$this->cache = new Memcache;

$config = Egysolutions_registry::getConfigurationStatic();
$this->cache->connect($config['cache']['memcached_host'], $config['cache']['memcache_port']);
}

function __set($key, $value)
{
$this->cache->set($key, $value);
}

function __get($key)
{
return $cache->get($key);
}

function delete($key)
{
return $this->cache->delete($key);
}

function delete_all($key)
{
return $this->cache->flush;
}

function info()
{
$memcache->getStats()['bytes'];
}
}