Mind the Gap | Home | Introducing : MultiSelect

Filed under Lab on June 19, 2007 by Chris LoSacco

Introducing : AppCache

The application scope is a sweet spot when writing for the web, where caching can make or break (really break) an app. It's also a huge convenience when working with variables that are largely static during the life of the application. Some languages, like Coldfusion, provide this functionality out of the box--but PHP is lacking this feature.

Enter Chris Dary, programmer extraordinaire here at Arc90, with AppCache, a really nice PHP5 implementation of the application scope that leverages memcached for caching. You can get it, and check out some examples, over in the Arc90 lab.

Post a Comment Digg Del.icio.us

Trackback Pings (TrackBack URL for this entry)

http://www.arc90.com/cgi-bin/mt4/mt-tb.cgi/70.

Listed below are links to weblogs that reference Introducing : AppCache:

» AppCache for PHP5 from arc90 lab

Speed up your apps and have a convenient application-level scope with AppCache by Chris Dary, the seventh tool from the arc90 lab.... [Read More]

Tracked on June 19, 2007 1:01 PM

Comments

Thanks to 'caffinated' from ##php on irc.freenode.net for pointing out a minor race condition in cached keys.

If process A and B get their keys, A deletes a key, A updates, and then B updates, this can lead to incorrect data.

This should be fixed in the next version of the code, however for the moment AppCache should still be very usable and this will only occur under very specific conditions.

-Chris Dary

Posted on June 20, 2007 2:27 PM by Chris Dary


Trying out Appcache. One quick question that I can't get works. Sorry for my English. I have memcache installed and works fine. Both SimpleExample and ComplexExamples work fine too.

I'm trying to access the $app from global $app. In SimpleExample.php we set $app->sampleValue.="Foo";

Now in SimpleExample2.php I want to print that value.

global $app;

print_r($app->sampleValue);

That doesn't work. Nothing is print. register_globals is on for Php5. What I'm missing here?

-Enzo

Posted on October 21, 2007 9:07 PM by Enzo

Hey there Enzo,

If I had to take a guess, it'd be because you're probably not initializing $app within SimpleExample2.php

Either include a common file that will include this line:
$app = new Application('Sample Application Name');

or stick the above line in SimpleExample2.php so that it can connect to memcache successfully.

Posted on October 21, 2007 9:13 PM by Chris D


You are fast! I just see that all I need to do in the SimpleExample2.php page is:

require 'include/Application.php'; (I moved to my include dir)
$app = new Application('Sample Application Name');

and then I can access $app->sampleValue; from my page 2.

I don't need use keyword global at all in this case. So by giving same app string name in page 1 and page 2 here:

$app = new Application('Sample Application Name');

this means I will access same object in memcache correct?

This is very nice. I just started to play with memcache and was thinking of writing layer like this. Good job.

Posted on October 21, 2007 9:38 PM by Enzo

Glad I could help Enzo. :)

In fact, it sounds like you can make it even easier than you've got it.

If you put your $app initialization line into a configuration file, and then 'require' it at the beginning of every PHP file that needs to access it, you only have your initialization in one place, which is cleaner code.

Posted on October 21, 2007 9:57 PM by Chris D


Yes, thanks. I will require in every file as you said. I was just testing out.


Firestarter+Squid+Lighttpd+AppCache+Memcache+APC+PHP5+MYSQL5+CENTOS5 = we see how far this scales soon !

Posted on October 21, 2007 11:58 PM by Enzo

Post a Comment:

Mind the Gap | Main | Introducing : MultiSelect