Jump to content

Caching queries


Gazley
 Share

Recommended Posts

Hi there,

As I'm starting to work across pages, I'm seeing some cases where I might like to re-use queries or HTML fragments that in my original framework, I may have cached in properties of more globally accessible object references.

In templates, you're in a page-centric scenario and I wondered whether there is anything in the framework for stashing values for use across template processing?

Thanks!

Link to comment
Share on other sites

Just store them in a separate something.php file in the templates folder and then in your head.inc file at the top include it like this:

<?php include ('./something.php'); ?>
Link to comment
Share on other sites

Hi Pete,

Many thanks for responding! :)

I don't think I made myself clear. What I was referring to was caching the runtime results of queries, not their definitions, and possibly HTML fragments (generated on the fly) that might be used more than once in the same server-side hit.

Know what I mean?

Cheers

--Gary

Link to comment
Share on other sites

See the $session variable. You can store objects, but always have to be careful, like with objects that may reference others and ensuring those object's class definitions are present before they are instantiated in the session. ProcessWire's $session isn't much more than a wrapper on top of PHP's $_SESSION, and you can still use PHP's $_SESSION if you want to. More about objects in sessions here. Personally, I prefer to recreate objects myself on each request. It should be possible to do what you are asking to do but the details of it will be PHP-specific rather than ProcessWire-specific.

  • Like 1
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...