Understanding Caching

onelife69

Member
Hi all,

I'm a very new user of xenforo and already a massive fan of the software. I just wanted to ask what caching does as I've never come across before on the other software I've used.

The server I'm on has a raid 10 ssd setup which seems to be very fast, so I was think of using core and file caching until the forum size out grew this set up.

But what does caching do? Does it affect the look of the site or the freshness of viewable content.

Many thanks in advance
 
If I set up the cache as per the xenforo manual do the cached files automatically expire or do I need to give an expiration time?
 
XenForo takes care of everything for XenForo, and the web server where the caching mechanism is installed does the rest.

Basically caching for web apps is simplified to this:

(server) ------ (php) ------ (mysql) ------ (end-user)

You have a server with a programming language and a database on it, and an end-user that requests data from this server, php figures out which data to return and gets it from the file system or the database.

The end user sends a request, the php software checks if it's already cached, nope? Ok, gives the user what it wants and stores a temporary cache.

The same or another user sends an equal request, the php software checks if it's already cached, yes! Ok, great, instead of doing more processing with PHP to figure things out, and instead of querying the database with extra queries for data we already have, php just gets a result from the cache that's basically already rendered.

In the first situation the server load is increased for a certain amount, php is stressed a bit more, and mysql is under higher load. While very small, with 50 or 500 or 5000 users, this could eventually create a queue for the cpu / ram, and hard drive.

In the second situation the server load is increased, but less than the first situation. Because php has to do less work, and mysql has to do less work. So when it would normally create a queue for the cpu / ram / hdd, it's now less.

Caching basically lets you server pages to existing visitors faster, and basically to even more visitors.

Instead of putting a crate together to move a random amount of apples for a user,
you put one crate together and re-use it every time for any user to help them move a random amount of apples to their home.
 
I am not a caching expert, and if I am wrong I am sure others will point it out just fine.
XenForo has a lot of tricks in regards to caching, and if you have a VPS / dedicated solution and a busy enough web site it's certainly worth considering them.

I would also consider moving the templates into the file system for caching, APC and other cachers will certainly make good use of it. The option to push it to the file system (they are still edited the normal way!) is within the admin.php > options

In config.php, turn on xenforo caching, turn on APC or whatever caching mechanism you're using, and push templates to the file system. Those are three good steps to get started with.

Of course, if you expect to notice a significant increase in how pages are loaded, do realize that on a smaller site you might not notice that much of a difference as the server isn't under heavy load. And that the pages have to be loaded at least once in order to be cached.

You notice it when you realize after using the site for a day that you haven't noticed a sluggish behavior you might normally have on certain pages. regardless if there are 5 or 50 users online. This is just a behavior that's a bit tough to personally detect or recognize.
 
I have a few questions about Xenforo caching as described here. http://xenforo.com/help/cache/

Since I can't use an (Alternative PHP Cache) because of the way our managed VSP is set up, I would like to use this or a variation of ;


$config['cache']['enabled'] = true;
$config['cache']['frontend'] = 'Core';
$config['cache']['frontendOptions']['cache_id_prefix'] = 'xf_';
$config['cache']['backend'] = 'File';

My fist question is, the site is live and we have been using the default Xenforo setup which is using the database, the site is very active so what happens when I add the above to the config file exactly? I seem to remember an option in vBulletin that would convert database to file storage or back..

Second this is, do I need to create any special folders for the above, I see there is already a cache folder with sub directories, does Xenforo automatically put the new cached files in those directories when using the above?

Third question is I saw this posed to another thread,

$config['cache']['backendOptions']['hashed_directory_level'] = '1';

Has anyone used this with basic file caching and is it better then using $config['cache']['backend'] = 'File'; .. if so why, and what needs to be done to go this route?

Lastly, are there any drawbacks from going with the basic file cache system long term, as in errors, or board size..

Thanks in advance for any help.
 
On my test site, I had
Code:
$config['cache']['enabled'] = true;
$config['cache']['frontend'] = 'Core';
$config['cache']['frontendOptions']['cache_id_prefix'] = 'xf_';
in my config file, and it's pushing files to the /tmp directory on the server.

Code:
-rw-------  1 worthy  worthy      78 Apr  5 21:44 xf_---worthy_data_simpleCache
-rw-------  1 worthy  worthy    3160 Apr  5 21:44 xf_---worthy_data_smilies
-rw-------  1 worthy  worthy    1856 Apr  5 21:45 xf_---worthy_data_smilieSprites
-rw-------  1 worthy  worthy  151825 Apr  5 21:50 xf_---worthy_data_styles
-rw-------  1 worthy  worthy      69 Apr  5 21:44 xf_---worthy_data_threadPrefixes
-rw-------  1 worthy  worthy     101 Apr  5 21:44 xf_---worthy_data_trophyUserTitles
-rw-------  1 worthy  worthy    1124 Apr  5 21:44 xf_---worthy_data_userFieldsInfo
-rw-------  1 worthy  worthy   87797 Apr  5 21:46 xf_---worthy_xfCssCache_068bbfd1905e5cdc83a4a6656622017e20a3e5e5
-rw-------  1 worthy  worthy   85364 Apr  5 21:50 xf_---worthy_xfCssCache_0734a15ea66d25c535356ce8f379aa21d46e6277
-rw-------  1 worthy  worthy   18939 Apr  5 21:49 xf_---worthy_xfCssCache_1b3bda56616e2a9059294888828814dbf437f323
-rw-------  1 worthy  worthy    9201 Apr  5 21:52 xf_---worthy_xfCssCache_2e32a8ca1d9e54420188157d3b22846b08d1a52e
-rw-------  1 worthy  worthy   18246 Apr  5 21:46 xf_---worthy_xfCssCache_2ec6d1e849c3ab38812df38050d8684163109e28
-rw-------  1 worthy  worthy   13437 Apr  5 21:47 xf_---worthy_xfCssCache_3b3ac5113e51d54380a80490e26582f7ae3bf3df
-rw-------  1 worthy  worthy   18251 Apr  5 21:50 xf_---worthy_xfCssCache_3ca4ebb7bcc447bc181b40920379c674b146ac2f
-rw-------  1 worthy  worthy   17129 Apr  5 21:50 xf_---worthy_xfCssCache_3cdd21029f3b7268cba3b4666fcb542b6463c51c
-rw-------  1 worthy  worthy   84946 Apr  5 21:49 xf_---worthy_xfCssCache_42d24209c256c7df50bb6b7c980a5c37b7d23218
-rw-------  1 worthy  worthy   21854 Apr  5 21:50 xf_---worthy_xfCssCache_43502eaf9511dd8bd33e4782d90b299db5106a2b
-rw-------  1 worthy  worthy   24589 Apr  5 21:52 xf_---worthy_xfCssCache_590a326e4d2ab7d2884994e86e1a3ee602db0931
-rw-------  1 worthy  worthy    6240 Apr  5 21:52 xf_---worthy_xfCssCache_6eae86dd9fbe288eeb42129965643fb355007cb0
-rw-------  1 worthy  worthy   38021 Apr  5 21:53 xf_---worthy_xfCssCache_82ce460cb5c901d5b63f5a62ea425ff6d8b98a08
-rw-------  1 worthy  worthy    2580 Apr  5 21:53 xf_---worthy_xfCssCache_830af50a7baaec1f7e7a7e970c62e7fc9453a76f
-rw-------  1 worthy  worthy   17228 Apr  5 21:50 xf_---worthy_xfCssCache_9333f2e99a27c136cbd1a167d88e0fbd75feffff
-rw-------  1 worthy  worthy   18258 Apr  5 21:46 xf_---worthy_xfCssCache_9e8ad27810b6b4324f6f35e7dc4549019582d461
-rw-------  1 worthy  worthy   87837 Apr  5 21:45 xf_---worthy_xfCssCache_ce3bfc20c6e3b1077296a5b08c62dd4e65d7db08
-rw-------  1 worthy  worthy   13443 Apr  5 21:45 xf_---worthy_xfCssCache_d0bff7ba29211f2e956fb4e8e6143ccd3164d664
-rw-------  1 worthy  worthy   23100 Apr  5 21:58 xf_---worthy_xfCssCache_e51a79ba5c81ee70198c48bd18a321ebcc18dcba
-rw-------  1 worthy  worthy    2536 Apr  5 21:49 xf_---worthy_xfCssCache_f094e940b7ac0cee92e01c5a9d3c4bd86c691395
z22se@z22se.co.uk [/tmp]#

I've just added this:
Code:
$config['cache']['backend'] = 'File';
$config['cache']['backendOptions']['hashed_directory_level'] = '1';
to see what happens.

On my main site, I use Xcache, and not file caching.
 
OK, so adding the hashed_directory_level is basically creating sub folders in the /tmp directory to store the files in
Code:
drwx------  2 worthy  worthy    1024 Apr  6 19:55 xf_--3/
drwx------  2 worthy  worthy    1024 Apr  6 19:55 xf_--4/
drwx------  2 worthy  worthy    1024 Apr  6 19:55 xf_--5/
drwx------  2 worthy  worthy    1024 Apr  6 19:55 xf_--6/
drwx------  2 worthy  worthy    1024 Apr  6 19:55 xf_--7/
drwx------  2 worthy  worthy    1024 Apr  6 19:55 xf_--8/
drwx------  2 worthy  worthy    1024 Apr  6 19:55 xf_--9/
drwx------  2 worthy  worthy    1024 Apr  6 19:55 xf_--a/
drwx------  2 worthy  worthy    1024 Apr  6 19:55 xf_--c/
 
So this is the way to go?

$config['cache']['enabled'] = true;
$config['cache']['frontend'] = 'Core';
$config['cache']['frontendOptions']['cache_id_prefix'] = 'xf_';
$config['cache']['backend'] = 'File';
$config['cache']['backendOptions']['hashed_directory_level'] = '1';

Any problems with adding this on a live site with 15k posts?
 
Shouldn't be any issues, it will just start caching the files in the /tmp directory.

This is my full cache config on the test site
Code:
$config['cache']['enabled'] = true;
$config['cache']['frontend'] = 'Core';
$config['cache']['frontendOptions']['cache_id_prefix'] = 'worthy_';
$config['cache']['backend'] = 'File';
$config['cache']['backendOptions']['hashed_directory_level'] = '1';
 
Thanks MattW, you have been a massive help..

By the way, whats with the 'worthy_'; in your front end? Just a folder you would rather have the info in, I assume leaving the 'xf_'; is okay?
 
By the way, whats with the 'worthy_'; in your front end? Just a folder you would rather have the info in, I assume leaving the 'xf_'; is okay?
Yeah, leaving the standard xf_ is fine, as that is what I have in my main site. The test site has worthy_ because that is the name of the account on the server, so they are separate if the main site needs to fall back to file caching.
 
Top Bottom