Jump to content

Archived

This topic is now archived and is closed to further replies.

yonta

Cache_Lite troubles

Recommended Posts

Hi :)

I simply can't solve this. i'm trying to use pear's Cache_lite for the first time but it is unable to correctly remove cache files and detect if the cache file is good. I mean 'correctly' remove because it does empty the file but doesn't remove it and when a new call to cache->get is made, it just shows an empty page.

When a call to remove or clean is made, it echos 'unable to remove cache file'. I've even tried setting the permission to 777 on the cache directory but to no avail.

Of course, if i turn off caching everything works.

My php version is 4. Please please help

Here's my script (part of the whole controller script):

[code]
function banners_Controller()//contructor
{
$this->objCache = new Cache_Lite(array('cacheDir' => 'cache/',
'lifeTime' => 3600,
'automaticCleaningFactor '=>100,
'pearErrorMode' => CACHE_LITE_ERROR_DIE));
}
function banners_List()
{
if (CACHING === true && $data = $this->objCache->get('ban_list','banners', false))
{
echo($data);
} else {

$this->_start();//include some scripts & set some variables
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'): $data =$this->tpl->display('banners_list.tpl.php');
CACHING == true? $this->objCache->save($data, 'ban_list'):'';
return true;
exit();
}
function banners_Insert($ban_photo, $ban_ispub)
{
if(empty($ban_photo) || $ban_ispub=='')
{
$_SESSION['feedback'] = 'Não se esqueça de seleccionar a imagem.';
$this->banners_List();
return false;
}
$this->_start();
require 'fileupload.class.php';

//clear cache
CACHING == true? $this->objCache->remove('ban_list','banners'):'';
CACHING == true? $this->objCache->clean():'';


//upload
$upload = new FileUpload($ban_photo, SPATH_TO_BANNERS_IMAGES, 'jpg');
$new_name = $upload->rename_filename();
$result = $upload->upload($new_name);
if($result[0]=== false)
{
$_SESSION['feedback'] = $result[1];
$this->banners_List();
return false;
}


//insert into db
$db_insert = $this->banners->banners_Insert('ban_'.$new_name, $ban_ispub);
if($db_insert === false)
{
$_SESSION['feedback'] = 'Erro ao guardar novo banner.';
$this->banners_List();
return false;
}
$_SESSION['feedback'] = 'Banner inserido com sucesso!';
$this->banners_List();
}
[/code]

Thanks for [b]any [/b]help

Share this post


Link to post
Share on other sites
I re-worked the directories and it no longer gives me that error.
I had
Classes ->
Lite.php
Cache ->
File.php
And i now have
Classes ->
 Cache ->
 Lite.php
 Lite ->
  File.php

But my script is still weird.
After a remove of the cache, the next time it calls get, it will simply output a blank page instead of regenerating the cache. I have to hit Refresh to view the built page.

So what happens is this: i view the page with the list of banners, next i delete a banner ($_GET request from link), it deletes the banner and shows an empty page, i hit refresh button in browser, and view the banner's list with the message that the banner has been deleted. Again, if i remove the cache everyting's fine.

Why? Any clues?

update: here's the delete function

[code]
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();

}
[/code]

Share this post


Link to post
Share on other sites
Well, it's probably of no interest to anyone but i'll just post it in case anyone runs into this using the same setup - phpSavant for templates and Cache_Lite for caching.

The only problem was not Cache_lite related but Savant related. I thought Savant's fetch method executed, displayed the output, and last returned the output but no - it doesn't display. I had to always use ->display(); So the problem was this (in banners_List() method):

CACHING == true? $data = $this->tpl->fetch('banners_list.tpl.php'): $data =$this->tpl->display('banners_list.tpl.php');

where instead i should have just done this
[code]
CACHING == true? $data = $this->tpl->fetch('banners_list.tpl.php'); //if caching is on fetch the output into variable $data
$data =$this->tpl->display('banners_list.tpl.php'); //displays the output - this should always run, caching or not
CACHING == true? $this->objCache->save($data, 'ban_list'):''; //if caching is on save the output in cache file
[/code]

Share this post


Link to post
Share on other sites

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.