How to Set Headers to Cache Search Results

285 views
Skip to first unread message

Julie H

unread,
Dec 3, 2010, 1:25:01 AM12/3/10
to Joomla! General Development
How can I override the default joomla headers from within a custom
component? I would like to change

Expires: Mon, 1 Jan 2001 00:00:00 GMT
Cache-Control: no-store, no-cache, must-revalidate, post-check=0, pre-
check=0
Pragma: no-cache

to

Expires: ~in five hours~
Cache-Control: public
Pragma: public

In my component, I have included the following code

JResponse::setHeader('Expires', gmdate('D, d M Y H:i:s', time()
+(60*60*5)) . ' GMT',true);
JResponse::setHeader('Pragma', 'public',true);
JResponse::setHeader('Cache-Control','public',true);

but the page is still sending out the default joomla values for
Expires, Pragma, and Cache in the http header.

Any help would be greatly appreciated.

Thanks,
Julie

Sébastien D'Errico

unread,
Dec 3, 2010, 11:09:44 AM12/3/10
to joomla-de...@googlegroups.com
Hello everyone,

Does someone have an idea why the file that containt my class derived from JView is called view.html.php instead of view.php, I get: 500 - View not found?

Thanks,
Have a great day!
Sébastien

Sébastien D’Errico
IT Development Consultant
Mobile : (438) 882-8687
Email : seba...@hollox.net

Sébastien D'Errico

unread,
Dec 3, 2010, 11:13:58 AM12/3/10
to joomla-de...@googlegroups.com
Just found out that I erased

$document->getType()

in

$view = &$this->getView(SETTING::$View, $document->getType());

Thanks everyone.

Hello everyone,

--
You received this message because you are subscribed to the Google Groups "Joomla! General Development" group.
To post to this group, send an email to joomla-de...@googlegroups.com.
To unsubscribe from this group, send email to joomla-dev-gene...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/joomla-dev-general?hl=en-GB.


Andy Nagai

unread,
Dec 5, 2010, 12:25:19 AM12/5/10
to joomla-de...@googlegroups.com
I am also unable to set my headers using setheader().

I dont see any expire tags in my default joomla template.

Not finding much documentation on this.

Sam Moffatt

unread,
Dec 5, 2010, 2:52:42 AM12/5/10
to joomla-de...@googlegroups.com
Pretty certain JResponse::setHeader is what you're after:
http://api.joomla.org/Joomla-Framework/Environment/JResponse.html#setHeader

Cheers,

Sam Moffatt
http://pasamio.id.au

Sam Moffatt

unread,
Dec 5, 2010, 3:12:25 AM12/5/10
to joomla-de...@googlegroups.com
Just looking at things, you also might want to set
JResponse::allowCache(true) as well to prevent JResponse setting those
headers as well.

Cheers,


Sam Moffatt
http://pasamio.id.au

Julie H

unread,
Dec 5, 2010, 9:57:49 PM12/5/10
to Joomla! General Development
JResponse::allowCache(true) did the trick. If it helps anyone else,
here is the code that worked for me.

JResponse::allowCache(true);
JResponse::setHeader('Pragma', 'public',true);
JResponse::setHeader('Cache-Control','public',true);
JResponse::setHeader('Expires', gmdate('D, d M Y H:i:s', time()
+(60*60*5)) . ' GMT',true);

Thanks!
Julie


On Dec 5, 3:12 am, Sam Moffatt <pasa...@gmail.com> wrote:
> Just looking at things, you also might want to set
> JResponse::allowCache(true) as well to prevent JResponse setting those
> headers as well.
>
> Cheers,
>
> Sam Moffatthttp://pasamio.id.au
>
>
>
> On Sun, Dec 5, 2010 at 5:52 PM, Sam Moffatt <pasa...@gmail.com> wrote:
> > Pretty certain JResponse::setHeader is what you're after:
> >http://api.joomla.org/Joomla-Framework/Environment/JResponse.html#set...
>
> > Cheers,
>
> > Sam Moffatt
> >http://pasamio.id.au
>
> > On Sun, Dec 5, 2010 at 3:25 PM, Andy Nagai <andy.na...@gmail.com> wrote:
> >> I am also unable to set my headers using setheader().
>
> >> I dont see any expire tags in my default joomla template.
>
> >> Not finding much documentation on this.
>

elin

unread,
Dec 6, 2010, 3:03:11 AM12/6/10
to Joomla! General Development
Added as an example here:

http://docs.joomla.org/API15:JResponse/allowCache

Thanks!

Elin

Andy Nagai

unread,
Dec 6, 2010, 8:42:32 AM12/6/10
to joomla-de...@googlegroups.com
That is awesome!

Thank you Sam and Elin

Andy
Reply all
Reply to author
Forward
0 new messages