Web Design Forum: Caching with APC - Web Design Forum

Jump to content

WDF
WDF Premium Memberships Reseller Hosting
Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

Caching with APC Rate Topic: -----

#1 User is online   rallport 

  • Web Guru
  • PipPipPipPipPip
  • Group: Members
  • Posts: 3,818
  • Joined: 03-January 10
  • Reputation: 266
  • Gender:Male
  • Location:England, UK
  • Experience:Advanced
  • Area of Expertise:Web Developer

Posted 22 December 2011 - 07:59 PM

Ok, so I'm now in the process of finally redoing out company website. THis time around we have a new server with APC enabled.

For caching I'd usually go down a file based router using pear cache lite, as it's simple and available to use on all servers.

In the past I've used APC briefly to cache a few arrays and variables - nothing major.

I've just come across a class that will cache the entire page output, using APC and then serve full pages from memory - which will obviously be a lot faster than a filoe basedf solution. See http://www.phpclasse...-using-APC.html

The pages on the site in question will be pretty static and will change weekly ish, but will be fairly complicated as the whole site is written using my CMS. So, the site would essentially always be served from cache until I manually clear it.

Anyway, can anyone forsee any issues with this?
0

#2 User is offline   KieranA 

  • Advanced Member
  • PipPipPip
  • Group: Members
  • Posts: 361
  • Joined: 11-November 09
  • Reputation: 7
  • Gender:Male
  • Experience:Nothing
  • Area of Expertise:Nothing

Posted 01 January 2012 - 05:06 PM

APC is a good idea - however, what happens if memory is emptied on the server? Here is what I would recommend:

1. Check APC to see if the key/data exists
2. If #1 returns false, select from database.
3. After #2 save to memory via APC.

You don't need a special class to cache data, you could quite simply buffer the output of the view, example:



// Is it already saved in memory?
$content = apc_fetch('page_name');

if ($content) {
    echo $content;
    exit;
}
// otherwise query the database...
ob_start();

echo $data_from_database;

$data = ob_get_contents();
apc_store('page_name', $data);

This post has been edited by KieranA: 01 January 2012 - 05:06 PM

0

#3 User is online   rallport 

  • Web Guru
  • PipPipPipPipPip
  • Group: Members
  • Posts: 3,818
  • Joined: 03-January 10
  • Reputation: 266
  • Gender:Male
  • Location:England, UK
  • Experience:Advanced
  • Area of Expertise:Web Developer

Posted 01 January 2012 - 10:33 PM

View PostKieranA, on 01 January 2012 - 05:06 PM, said:

APC is a good idea - however, what happens if memory is emptied on the server? Here is what I would recommend:

1. Check APC to see if the key/data exists
2. If #1 returns false, select from database.
3. After #2 save to memory via APC.

You don't need a special class to cache data, you could quite simply buffer the output of the view, example:



// Is it already saved in memory?
$content = apc_fetch('page_name');

if ($content) {
    echo $content;
    exit;
}
// otherwise query the database...
ob_start();

echo $data_from_database;

$data = ob_get_contents();
apc_store('page_name', $data);



Yer, that's essentially what the class does, but a little cleaner.

Just wondered if anyone saw any issues with this, as I'm caching whole pages using APC which will take up more memory.
0

#4 User is offline   KieranA 

  • Advanced Member
  • PipPipPip
  • Group: Members
  • Posts: 361
  • Joined: 11-November 09
  • Reputation: 7
  • Gender:Male
  • Experience:Nothing
  • Area of Expertise:Nothing

Posted 01 January 2012 - 10:41 PM

View Postrallport, on 01 January 2012 - 10:33 PM, said:

Yer, that's essentially what the class does, but a little cleaner.

Just wondered if anyone saw any issues with this, as I'm caching whole pages using APC which will take up more memory.


If it's only HTML then you should be fine - but to be sure you should run a quick audit on the site and figure out the overall size of the dataset.

This post has been edited by KieranA: 01 January 2012 - 10:43 PM

0

#5 User is online   rallport 

  • Web Guru
  • PipPipPipPipPip
  • Group: Members
  • Posts: 3,818
  • Joined: 03-January 10
  • Reputation: 266
  • Gender:Male
  • Location:England, UK
  • Experience:Advanced
  • Area of Expertise:Web Developer

Posted 02 January 2012 - 10:07 AM

That's the main thing I'm worried about really - haven't really been able to find any guidelines on it either. All the documentation seems to be for caching key/values :(
0

#6 User is offline   KieranA 

  • Advanced Member
  • PipPipPip
  • Group: Members
  • Posts: 361
  • Joined: 11-November 09
  • Reputation: 7
  • Gender:Male
  • Experience:Nothing
  • Area of Expertise:Nothing

Posted 02 January 2012 - 01:36 PM

View Postrallport, on 02 January 2012 - 10:07 AM, said:

That's the main thing I'm worried about really - haven't really been able to find any guidelines on it either. All the documentation seems to be for caching key/values :(


The value simply means any data. It'll be fine, store your HTML in APC :)
0

#7 User is online   rallport 

  • Web Guru
  • PipPipPipPipPip
  • Group: Members
  • Posts: 3,818
  • Joined: 03-January 10
  • Reputation: 266
  • Gender:Male
  • Location:England, UK
  • Experience:Advanced
  • Area of Expertise:Web Developer

Posted 05 January 2012 - 06:26 PM

View PostKieranA, on 02 January 2012 - 01:36 PM, said:

The value simply means any data. It'll be fine, store your HTML in APC :)


Ah see what you mean. When I used it, it was literally a key (such as count of x) and a value like 999 :)
0

Share this topic:


Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users