Ravens PHP Scripts: Forums
 

 

View next topic
View previous topic
Post new topic   Reply to topic    Ravens PHP Scripts And Web Hosting Forum Index -> How To's
Author Message
beetraham
Regular
Regular



Joined: Dec 13, 2003
Posts: 94
Location: Finland (EU)

PostPosted: Thu Oct 14, 2004 11:41 am Reply with quote

How-To apply CACHE_LITE both SELECTIVELY and CONDITIONALLY for PHP-Nuke?

In the next, we're about to pass through (3) different PHP-Nuke Block structures, which are related to following CACHE_LITE application scenarios as follows;

Please note, that whereas the *JPCACHE* is in a sense restricted to be used for entire web pages, CACHE_LITE provides possibilities and methods for both the selective PHP-Nuke BLOCK caching (only certain block are cached) and for conditional PHP-Nuke BLOCK caching (caching applied depending on the site visitor *user status*).

Neither of the applications is restricted to what is presented in the next - as a matter fact there extraordary possibilities seen with the use of JPCACHE, which however is is out of context herein.

So, let's pass quickly through some practical EXAMPLES, which can be productively applied with cache configurations related to PHP-Nuke.

::: INTRO :::

PHP-Nuke Block, standard [reference only, non-CACHED version][/b]
* standard, non-cached version

This form is applied for all user statuses, when there's no associated cache utilization (anonymous, USER, ADMIN)

PHP-Nuke Block, non-user STATUS based caching
* cached, user status independent form of caching.

This form is generally applied for all user statuses (anonymous, USER, ADMIN) to speed up the site performance for all site visitors.

PHP-Nuke Block, user STATUS based caching
* cached, user status dependent form of caching.

This form is generally applied for user status (anonymous) to speed up the site performance for non-logged-in site visitors.

EXAMPLE PHP-Nuke Configurations; [SELECTIVE AND CONDITIONAL CACHING COMBINED]
Quote:

PHP-Nuke Block : "Site Info"
* standard, non-cached version
===> all visitor share "up-to-date" information, regarless of the *user* STATUS


Quote:

PHP-Nuke Block : "Shout Block"
* standard, non-cached version
* cached, user status dependent form of caching.
===> *user status' : "anonymous" <= "cached" [+ disabled active interaction, not allowed to send messaged...]
===> *user status' : "USER" <= "non-cached"
===> *user status' : "ADMIN" <= "cached"

<=> there's no reason to expect Site Admin to actively utilize this block while logged in as ADMIN - additionally, ADMIN view equals to USER view <=> no annoyances expected in case of occured caching.


Quote:

PHP-Nuke Block : "Last Referrer"
* standard, non-cached version
* cached, user status dependent form of caching.
===> *user status' : "anonymous" <= "cached"
===> *user status' : "USER" <= "cached"
===> *user status' : "ADMIN" <= "non-cached"

<=> this block MUST NOT be cached while logged in as ADMIN, i.e. we do not wish to set visible ADMIN STATUS associated view to BLOCK specifics - this chance is always present with each block configured to be cached for ADMINS as well. You should carefully pass through the BLOCK LINE-UP which is allowed to be cached while logged in as ADMIN - there are pleaty of those BLOCKS to cached for ADMINS as well, but some of those BLOCKS necessarily need to be left out of the ADMIN STATUS associated caching scene.


So, the above was just to give an idea of the beneficial forms of PHP-Nuke BLOCK caching configurations and possibilities related to it.


::: BLOCK EXAMPLES :::

The attached "reduced" examples beneath are presented in an attempt to provide a viewpoint to mutual strucutres and the associated differencies - those examples speak well for themselves, hence we'll just present the EXAMPLE structures underneath. This presentation is an summary and extension of what has already been seen and discussed in these Forums and others related to CACHE_LITE utilization. Thanks for all that have given their input related to PHP-Nuke caching so far!

The most significant add-on clarification can be associated in form of presented Last Section - PHP-Nuke Block, user STATUS based caching.

So, here are CACHE_LITE utilization related structures - you'll find definately useful to apply the CACHE_LITE - in both presented ways of caching.

Quote:

PHP-Nuke Block, standard [reference only, non-CACHED version]
* standard, non-cached version
Quote:

<?php
if (eregi("block-EXAMPLE.php",$PHP_SELF)) {
Header("Location: index.php");
die();
}

//////////////////////////////////////////////////////////////
// //
// YOUR VIRTUAL STANDARD PHP-NUKE BLOCK CONTENT GOES HERE //
// //
//////////////////////////////////////////////////////////

?>




Quote:

PHP-Nuke Block, non-user STATUS based caching
* cached, user status independent form of caching.
Quote:

<?php
if (eregi("block-EXAMPLE.php",$PHP_SELF)) {
Header("Location: index.php");
die();
}
//////////////////////////////////
// BEGINNING OF CACHE *HEADER* //
////////////////////////////////
//
// include the Cache-Lite package //
//
require_once("includes/Cache_Lite/Lite.php");
//
// set some variables
//
$options = array(
"cacheDir" => "/tmp/Cache_Lite/",
"lifeTime" => 900
);
// create a Cache_Lite object
//
$objCache = new Cache_Lite($options);
//
// test if there exists a valid cache, the ID will be the basename of the block
//
$fileid = basename($blockfile,".php");
//
if ($content = $objCache->get($fileid)) {
/////////////////////////////////////////////////////
// add a message indicating this is cached output //
///////////////////////////////////////////////////
//
$content .= "<br><center>[cached information]</center>";
} else {
// do the block's work, in case that there's a need to update the cache
//
////////////////////////////
// END OF CACHE *HEADER* //
//////////////////////////

//////////////////////////////////////////////////////////////
// //
// YOUR VIRTUAL STANDARD PHP-NUKE BLOCK CONTENT GOES HERE //
// //
//////////////////////////////////////////////////////////

//////////////////////////////////
// BEGINNING OF CACHE *FOOTER* //
////////////////////////////////
//
// if we are about to update the CACHE...
// ...we'll then save the content in cache for future usage
$objCache->save($content, $fileid);
//
//////////////////////////////////
// END OF CACHE *FOOTER* //
////////////////////////////////

}
?>




Quote:

PHP-Nuke Block, user STATUS based caching
* cached, user status dependent form of caching [highly recommended]
Quote:

<?php
if (eregi("block-EXAMPLE.php",$PHP_SELF)) {
Header("Location: index.php");
die();
}
////////////////////////////////////
// EVALUATING USER ONLINE STATUS //
//////////////////////////////////

global $user, $admin, $cookie;
$username = $cookie[1];

if (is_admin($admin)) {
$showcache ="off"; // no cached information for SITE *ADMINS*!
} elseif ($username == "") {
$showcache ="on"; // we'll provide cached information for SITE *VISITORS*
} else {
$showcache ="off"; // no cached information for SITE *USERS*
}
$content = ""; // initial variable declaration

////////////////////////////////////////////////////////////////////////
// |-------> BEGINNING OF CONDITIONALLY APPLIED *CACHE_LITE* SECTION //
//////////////////////////////////////////////////////////////////////
//
//////////////////////////////////
// BEGINNING OF CACHE *HEADER* //
////////////////////////////////

$cacheupdate ="off"; // initial variable declaration, just for the sake of clarity

if ($showcache =="on") {
//
// include the Cache-Lite package
//
require_once("includes/Cache_Lite/Lite.php");
//
// set some variables
//
$options = array(
"cacheDir" => "/tmp/Cache_Lite/",
"lifeTime" => 900
);
// create a Cache_Lite object
//
$objCache = new Cache_Lite($options);
//
// test if there exists a valid cache, the ID will be the basename of the block
//
$fileid = basename($blockfile,".php");
if ($content = $objCache->get($fileid)) {
////////////////////////////////////////////////////
// add a message indicating this is cached output //
///////////////////////////////////////////////////
$content .= "<br><center>[cached information]</center>";
} else {
$cacheupdate ="on"; // this assignment functions as a key to "cache update"
// do the block's work, as the need for updating the cache is indicated by $cacheupdate "on" value
//
////////////////////////////
// END OF CACHE *HEADER* //
//////////////////////////
}
}

// we'll never pass the next gatekeepers to STANDARD BLOCK ARCHITECTURE , UNLESS...
// (1) ...we are logged in as a USER or as a ADMIN (or)
// (2) ...we are about to UPDATE THE EXPIRED CACHE

if ($showcache =="off" || $cacheupdate =="on") {

//////////////////////////////////////////////////////////////
// //
// YOUR VIRTUAL STANDARD PHP-NUKE BLOCK CONTENT GOES HERE //
// //
//////////////////////////////////////////////////////////


//////////////////////////////////
// BEGINNING OF CACHE *FOOTER* //
////////////////////////////////
//
// if we are about to update the CACHE...
if ($cacheupdate =="on") {
// ...we'll then save the content in cache for future usage
$objCache->save($content, $fileid);
//
//////////////////////////////////
// END OF CACHE *FOOTER* //
////////////////////////////////
}
}
//////////////////////////////////////////////////////////////////
// |-------> END OF CONDITIONALLY APPLIED *CACHE_LITE* SECTION //
////////////////////////////////////////////////////////////////
?>




All's well that ends well.

Thanks,

-beetraham

_________________
- Let there be no windows at your home - 
View user's profile Send private message
Raven
Site Admin/Owner



Joined: Aug 27, 2002
Posts: 17088

PostPosted: Thu Oct 14, 2004 12:24 pm Reply with quote

As a further note, I am starting on a project to create an Admin panel for Cache_Lite. I am still in the design stage, but it will allow for selective clearing of the cached files. In addition, I hope to simplify the addition process.

On another note, we need to figure out how to cache modules. For instance, imagine the savings if the News could be cached Smile
 
View user's profile Send private message
beetraham







PostPosted: Thu Oct 14, 2004 4:26 pm Reply with quote

Raven wrote:
As a further note, I am starting on a project to create an Admin panel for Cache_Lite. I am still in the design stage, but it will allow for selective clearing of the cached files. In addition, I hope to simplify the addition process.

On another note, we need to figure out how to cache modules. For instance, imagine the savings if the News could be cached Smile


OK, that sounds great - looking forward to it. Smile

I'd like extend a little bit the earlier presented *cache structs* - the below may well be the most efficient form of incorporating *CACHE_LITE*, prior to implementing it configurable via Admin Panel, just as Raven referrered in the above post.

AFAIC, the most easiest method to effectively incorporate *fixed cache architecture utilization* (in case of CACHE_LITE and presented PHP-Nuke BLOCK structs)would be to slice out the presented *cache header* and *cache footer* structures into INCLUDE FILES, which would be then added to corresponding *include statement sections* - in case that active file caching would be considered as an option to use.

In other words:

Quote:
<?php
if (eregi("block-EXAMPLE.php",$PHP_SELF)) {
Header("Location: index.php");
die();
}

include "cache_header"; <--- stuff in the proper config, and "read it" in...

//////////////////////////////////////////////////////////////
// //
// YOUR VIRTUAL STANDARD PHP-NUKE BLOCK CONTENT GOES HERE //
// //
//////////////////////////////////////////////////////////

include "cache_footer"; <--- stuff in the proper config, and "read it" in...

?>


As noticed earlier, there are at least the following configurations available (the most realistic ones presented in the next):

Quote:
CONF-#1
"use cache" status : anon. : [yes]
"use cache" status : user : [yes]
"use cache" status : admin : [yes]

CONF-#2
"use cache" status : anon. : [yes]
"use cache" status : user : [no]
"use cache" status : admin : [yes]

CONF-#3
"use cache" status : anon. : [yes]
"use cache" status : user : [yes]
"use cache" status : admin : [no]

CONF-#4
"use cache" status : anon. : [no]
"use cache" status : user : [no]
"use cache" status : admin : [yes]

CONF-#5
"use cache" status : anon. : [no]
"use cache" status : user : [no]
"use cache" status : admin : [no]


So, in order to achieve flexible command over the above configurations BLOCK specifically, one should create (5)pcs of *cache-header-footer* pairs in order to bypass all the unnecessary repetition of *cache structure* copy/paste session - as being said, this may usable prior to Raven's Admin Panel Application release for Cache Lite.

I'll now begin constructing these *interim* add-ons, and I'll let you know as soon those are available - equipped with this kind of minor introduction - it'll take a couple of hours to test 'em prior to packing - the release will cover the *cache_header* and *cache_footer* parts for yours to apply.

Naturally, this is not a big deal, but still a step forward in the interim towards more a faster and reliable control over cache (Cache_Lite) empowered PHP-Nuke

Well - that's basically what I wanted to add herein, I hope I had it all said.

-beetraham
 
beetraham







PostPosted: Fri Oct 15, 2004 6:47 am Reply with quote

So, this is what I'm coming up during the few hours - the package wil include th following content:

Quote:

* blocks/block-Cache_Lite_TEST_EXAMPLE_0-0-0.php
* blocks/block-Cache_Lite_TEST_EXAMPLE_0-0-1.php
* blocks/block-Cache_Lite_TEST_EXAMPLE_0-1-0.php
* blocks/block-Cache_Lite_TEST_EXAMPLE_0-1-1.php
* blocks/block-Cache_Lite_TEST_EXAMPLE_1-0-0.php
* blocks/block-Cache_Lite_TEST_EXAMPLE_1-0-1.php
* blocks/block-Cache_Lite_TEST_EXAMPLE_1-1-0.php
* blocks/block-Cache_Lite_TEST_EXAMPLE_1-1-1.php

* includes/cache_lite_header_0-0-0.php
* includes/cache_lite_header_0-0-1.php
* includes/cache_lite_header_0-1-0.php
* includes/cache_lite_header_0-1-1.php
* includes/cache_lite_header_1-0-0.php
* includes/cache_lite_header_1-0-1.php
* includes/cache_lite_header_1-1-0.php
* includes/cache_lite_header_1-1-1.php
* includes/cache_lite_footer.php

* includes/cache_configuration_check.php [shared check architecture performing the EXAMPLE BLOCKS related checks, used as an include within the EXAMPLE BLOCK architectures]



Ths meaning what? What does it resolve?

Well, basically that ALL the possible ADMIN-USER-ANONYMOUS combination/permutations are covered related to *enhanced utilization* of *Cache_Lite* targetted for PHP-Nuke cached BLOCK configuration scenes.

The appraoch, as applied, will speed up the initial configuration stage efforts, as well as the efforts needed when choosing to apply altered Cache_Lite caching strategy for PHP-Nuke BLOCKS. It'll also reduce the amount of needed efforts when choosing to give up from using Cache_Lite.

But, hey seriously - who would like to give up from using Cache_Lite? Wink

What is then required to be changed/added in/to standard PHP-Nuke BLOCKS?

When applied to STANDARD PHP-Nuke BLOCKS, the *enhanced cache utilization* BLOCK strucutre will have a great reseblence to following struct AT ALL CASES:

Legend : [x-x-x] == {0-0-0, 0-0-1,...,1-1-1} [cache configuration identifiers]

Quote:

<?php
if (eregi("block-EXAMPLE_[x-x-x].php",$PHP_SELF)) {
Header("Location: index.php");
die();
}
include "includes/cache_lite_header_[x-x-x].php"; // cache header section related to this *Cache_Lite* config
//
if ($showcache =="off" || $cacheupdate =="on") {


//////////////////////////////////////////////////////////////
// //
// YOUR VIRTUAL STANDARD PHP-NUKE BLOCK CONTENT GOES HERE //
// //
//////////////////////////////////////////////////////////

include "includes/cache_lite_footer.php"; // cache footer section related to this *Cache_Lite* config
}

?>


What about the BLOCKS then - the ones that have been included within the package?

OK, then...so, the purpose of those BLOCKS is to have an immediate chance for verifying the PACKAGE VALIDITY (and possibly the existing Cache_Lite environment) in terms of using this package actively with BLOCKS to be modified for this utilization approach.

As each of the package associated EXAMPLE BLOCKS is fixed to using a certain CACHE STRATEGY only, you'll therfore have a flexible chance to verify the validity of each applied *CACHE CONFIGURATION* by examining each BLOCK per altering your Site User Status - depending on the chosen BLOCK (cache configuration line-up) - and your USER STATUS (ADMIN, USER, ANONYMOUS), you'll get to see either CACHED or NON-CACHED VERSION of the BLOCK.

Just for the sake of curiosity, a screenshot related to configuguration 1-0-0 (admin CACHED, user NON-CACHED, anonymous NON-CACHED) is shown in the next:

Image

BR,

-beetraham

[Oct-16th-2004]

OK, so the package is now released - it took a while longer, since I figured that it might be beneficial to incorporate the package with a testbench, *a testbench* for *Cache_Lite* environment validation purposes.

Perhaps not a "testbench" in it's strict sense of meaning, but still a set of EXAMPLE-BLOCKS, each using a unique available *configuration cache-header include file*, in a fixed way. This allows Site Admin to pass through the results at his end, prior to active utilization, thus ensuring/validating that both the environment has been setup properly and that the actual *wrapper package* is incorporated with functionality as stated in the README-INSTALL.html*. There are sceptics out there, and that's not necessarily a bad thing at all. Smile However, the Regression Stage results equal to the ones expected per "specification" (README-INSTALL.html) - so, time will show, whether there's any use for that wrapper package.

Onilne version of the README-INSTALL.html:
Only registered users can see links on this board! Get registered or login!

BR,

-beetraham
 
Display posts from previous:       
Post new topic   Reply to topic    Ravens PHP Scripts And Web Hosting Forum Index -> How To's

View next topic
View previous topic
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You can attach files in this forum
You can download files in this forum


Powered by phpBB © 2001-2007 phpBB Group
All times are GMT - 6 Hours
 
Forums ©