Hi, how can i disable cache in one View? I have a module very dinamically generated (editviewdefs), so i have problem with the cache. Is there a way to disable (or regenerate) cache for this view (EditView)?
UP :dry:
I do this in a custom view.detail.php to force the cache to clear - seems to work.
public function display(){
//do some programming logic
$repair= new RepairAndClear();
$repair->repairAndClearAll(array('clearAll'),array(translate('LBL_ALL_MODULES')), true,false);
parent::display();
}
Hi guys,
I would like to suggest an alternative solution, that does not require doing a repair and rebuild
First thing is to extend the TemplateHandler. Can place it in custom/include/TemplateHandler/CustomTemplateHandler.php, for instance.
The code I have here allows you to re-use this custom template handler and enable/disable the template parsing using a field. But you are free to have another solution.
// custom/include/TemplateHandler/CustomTemplateHandler.php
<?php
require_once 'include/TemplateHandler/TemplateHandler.php';
class CustomTemplateHandler extends TemplateHandler
{
public $disableCheckTemplate = false;
/**
* Override checkTemplate
* @see TemplateHandler::checkTemplate()
*/
function checkTemplate($module, $view, $checkFormName = false, $formName = '')
{
if ($this->disableCheckTemplate === true){
return false;
}
return parent::checkTemplate($module, $view, $checkFormName, $formName);
}
}
Then, for your module extend the view you want (Detail or Edit). Leave here the two examples:
DetailView:
First override the core DetailView2
// custom/include/DetailView/CustomDetailView.php
<?php
require_once('include/DetailView/DetailView2.php');
class CustomDetailView extends DetailView2
{
/**
* Override setup
* @see DetailView2::setup()
*/
public function setup($module, $focus, $metadataFile = null, $tpl = 'include/DetailView/DetailView.tpl')
{
parent::setup($module, $focus, $metadataFile, $tpl);
require_once 'custom/include/TemplateHandler/CustomTemplateHandler.php';
$this->th = new CustomTemplateHandler();
$this->th->ss = $this->ss;
}
}
The add an detail view extension to your module (in this example Iām using is Accounts)
And set the disableCheckTemplate to true when you want.
// custom/modules/Accounts/views/view.detail.php
<?php
require_once('include/MVC/View/views/view.detail.php');
class AccountsViewDetail extends ViewDetail
{
/**
* Override preDisplay
* @see ViewDetail::preDisplay()
*/
public function preDisplay()
{
$metadataFile = $this->getMetaDataFile();
require_once 'custom/include/DetailView/CustomDetailView.php';
$this->dv = new CustomDetailView();
$this->dv->ss = &$this->ss;
$this->dv->setup($this->module, $this->bean, $metadataFile, get_custom_file_if_exists('include/DetailView/DetailView.tpl'));
}
/**
* Override display
* @see ViewDetail::display()
*/
public function display(){
$this->dv->th->disableCheckTemplate = true;
parent::display();
}
}
For the editview
First override the core EditView2
// custom/include/EditView/CustomEditView.php
<?php
require_once 'include/EditView/EditView2.php';
class CustomEditView extends EditView
{
/**
* Override getTemplateHandler
* @see EditView::getTemplateHandler()
*/
protected function getTemplateHandler()
{
require_once 'custom/include/TemplateHandler/CustomTemplateHandler.php';
return new CustomTemplateHandler();
}
}
The add an edit view extension to your module (in this example Iām using is Accounts)
And set the disableCheckTemplate to true when you want.
<?php
require_once('include/MVC/View/views/view.edit.php');
class AccountsViewEdit extends ViewEdit
{
/**
* Override Display
* @see ViewEdit::display()
*/
public function display()
{
global $current_language;
$this->ev->th->disableCheckTemplate = true;
parent::display();
}
/**
* Override getEditView
* @see ViewEdit::getEditView()
*/
protected function getEditView()
{
require_once 'custom/include/EditView/CustomEditView.php';
return new CustomEditView();
}
}
Hope this helps. I think I didnāt miss anything, but if you have problems let me know.
thank you so much, i have solved in these way:
$repair= new RepairAndClear();
$repair->repairAndClearAll(array('clearThemeCache'),array(translate('LBL_MYMODULE')), true,false);
I clean only theme cache
Hi everybody, I came about the same problem but ārepairAndClearAllā gives me an error because inside that function, the action ārepairDatabaseā is always called after the user actions. That action needs admin user to be executed, and If your view is available also for not administrator users, you will get āUnauthorized access to administration.ā error.
To solve I call directly the function I need:
require_once 'modules/Administration/QuickRepairAndRebuild.php';
$repair= new RepairAndClear();
$repair->show_output = false;
$repair->clearThemeCache();
parent::display();
Bye
I was looking for exactly this functionality recently. But Iām wondering with the code above if there is a race condition if there is more than one concurrent request. In that situation is it possible that the wrong cache file would be used for at least one of the requests, depending on the timing of the calls to repairAndClearAll?
If somebody gets this error message with the code aboveā¦
Warning: Declaration of
CustomDetailView::setup($module, $focus, $metadataFile = NULL, $tpl =
'include\/De...') should be compatible with
DetailView2::setup($module,
$focus = NULL, $metadataFile = NULL, $tpl = 'include\/De...',
$createFocus = true, $metadataFileName = 'detailview...')
in
/var/www/html/custom/include/DetailView/CustomDetailView.php
on line 0
then I suggest you change this line in your custom file
public function setup($module, $focus, $metadataFile = null, $tpl = 'include/DetailView/DetailView.tpl')
to
public function setup($module, $focus = null, $metadataFile = null, $tpl = 'include/DetailView/DetailView.tpl', $createFocus = true, $metadataFileName = 'detailviewdefs')
require_once 'modules/Administration/QuickRepairAndRebuild.php';
$repair= new RepairAndClear();
$repair->show_output = false;
$repair->clearThemeCache();
parent::display();
Hi @loba85 @gitbnw thank you for your help It“s working for me!!! Regards from Cali, Colombia
Great discussion. I had the same issue. Iām trying to solve it now, thanks.