Page 1 of 1

Help with Cache_lite

Posted: Thu Sep 28, 2006 2:14 pm
by yonta
Hi :)

I simply can't solve this. i'm trying to use pear's Cache_lite for the first time and i've encountered a problem that i think i probably is due to the logic of my script but i can't solve it.

I have a page with a list of banners, if i delete a banner ($_GET request from link), it deletes the banner and shows an empty page, if i then hit refresh button in browser, i view the banner's list with the message that the banner has been deleted.
This same sequence in my script would be:
view banner's list: function banners_List (tests if there's a cache - if not builds and saves page in cache)
delete banner: function banner_Delete(removes cache, deletes banner) -> function banners_List (tests if there's a cache - if not builds and saves page in cache)

If i remove the cache everyting's fine.

I'm using Savant for the templates & PHP4.

Here's my script (it's a controller class):

Code: Select all

function banners_Controller() //constructor
	{
		$this->objCache = new Cache_Lite(array('cacheDir' => 'tmp/',
									'lifeTime' => 3600,
									'automaticCleaningFactor '=>100,
									'pearErrorMode' => CACHE_LITE_ERROR_DIE));
	}

function banners_List()
	{
		if (CACHING === true && $data = $this->objCache->get('ban_list','banners'))
		{
			echo($data);
		} else {

			$this->_start(); //includes some scripts
			require 'Savant2.php';
			$this->tpl = new Savant2(array('template_path' => 'templates'));


			$list = $this->banners->banners_GetAll();
			$list === false ? trigger_error("Erro ao aceder à lista de banners.", E_USER_ERROR): '' ;

			$this->tpl->assign('banners', $list);
			$this->tpl->assign('path', LPATH_TO_BANNERS_IMAGES);
			CACHING == true? $data = $this->tpl->fetch('banners_list.tpl.php'): $this->tpl->display('banners_list.tpl.php');
			CACHING == true? $this->objCache->save($data, 'ban_list', 'banners'):'';

		}

	}
function banners_Delete($ban_id)
	{
		$this->_start();
		CACHING == true? $this->objCache->remove('ban_list','banners'):'';
		$result = $this->banners->banners_GetOne($ban_id);
		$image_name = $result['ban_photo'];
		if(!$result || $image_name=='')
		{
			$_SESSION['feedback'] = 'Banner escolhido não existe.';
			$this->banners_List();
			return false;
			exit();
		}
		@unlink(SPATH_TO_BANNERS_IMAGES.$image_name);
		unset($result);
		$result = $this->banners->banners_Delete($ban_id);
		if($result === false)
		{
			$_SESSION['feedback'] = 'Erro ao eliminar banner escolhido.';
			$this->banners_List();
			return false;
			exit();
		}
		$_SESSION['feedback'] = 'Banner eliminado com sucesso!';
		$this->banners_List();

	}
Please help.. i really need it.
[/list]