1

I'm looking to create a 'wrapper' function set where I call a function before code, then again after code in order to have it to isolate and perform actions on that contained code.

Specifically, I am creating a block caching tool for a custom content management engine that will allow template developers to specify certain areas of code that can and cannot be server side cached.

For example:

<?php
echo "test1";
echo "test2";

dontCacheStart();

echo "test3";
echo "test4";

dontCacheEnd();

echo "test5";
?>

Would generate a file on the server ...

test1test2<?php
echo "test3";
echo "test4";
?>test5

Which would then be accessed on subsequent page requests for faster processing (until it expires or is deleted).

I have all the other functionality operational, but do not know how to create a wrapper tag.

Thanks in advance for any advice!

2
  • Is using already functional and thoroughly tested templating engine out of the question? If not, you might want to check out Smarty, it already supports caching: smarty.net Commented Oct 21, 2013 at 18:36
  • You could implement it using goto's (the horror!) Commented Oct 21, 2013 at 19:02

1 Answer 1

1

You could use an output buffer to capture certain output, then call a function to cache that output. http://php.net/manual/en/function.ob-start.php

Sign up to request clarification or add additional context in comments.

1 Comment

Yes - and ob- is where I started this adventure Since the vast majority of the page would qualify to be 'cached' (processed immediately and store the result of the result of the processed code) while the areas with the 'wrappers' would not be cached (stored as the original code) with PHP beginning/end tags dropped into place as required, along with debugging code I would like to execute, I need more than only the ob- tags. This is why I am seeking I way to make my own wrapper class.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.