Getting started caching data in PHP

I use simpleXML to traverse the XML results of the Twitter XML file, but I completely lost the caching of the results using PHP. This article seems to help a little, but I met memcache (and memcached. C'mon, namers.) As well, and I have no idea what to do.

I use this:

$sxml = simplexml_load_file( 'http://api.twitter.com/1/qworky/lists/qworkyteam/statuses.xml'); foreach($sxml->status as $status){ $name = $status->user->name; $image = $status->user->profile_image_url; $update = $status->text; $url = "http://twitter.com/" . $status->user->screen_name; } 

just store the xml data on your twitter list in usable variables. But what is the right thing to do? Create a cache file and run this block only in PHP, if the cache file is older than ten minutes, otherwise execute cached variables? How to pass cached variables back and forth between a cached file and the DOM? Damn, what extension and file name does the cache file have?

Thanks so much for any way you can point me in a healthy direction here.

+5
php caching twitter
source share
2 answers

Joshua take a look at this article about simple PHP caching, you can do what you described with relative ease (and yes, probably the most sensible way to go).

+8
source share

As a general concept, caching does not imply an implementation strategy. A common idea is that you store information somewhere, which provides more efficient access than when you received the data initially.

So, in this case, it is more efficient to receive data from the disk than to request Twitter (usually, latency is greater than the latency of the IO disk).

In addition, retrieving data from memory is more efficient than retrieving information from a disk (since memory latency is less than the IO disk latency).

At the same time, you can save the values ​​from Twitter in memory, if you want, or to a file on disk, if you need values ​​that you need to save, not to mention shutdown. How you do this is up to you (disk or memory, extensions, format, etc. Etc.). This is your cache.

The thing you should be careful about is cache growing sluggishly. This is when the information that you have in your cache is not synchronized with the original data source. You must make a determination for your application how outdated data is acceptable, and require you to replace your cache values ​​as necessary.

+4
source share

All Articles