4images Forum & Community

4images Modifications / Modifikationen => Mods & Plugins (Requests & Discussions) => Topic started by: Kane on February 02, 2006, 03:54:56 PM

Title: Cache images page
Post by: Kane on February 02, 2006, 03:54:56 PM
As of now we can cache the gallery home page, the categories page, but NOT the images page itself. Why??? It seems obvious that the images page is the page that will be hit the hardest and therefore should be cached as well.
Title: Re: Cache images page
Post by: V@no on February 03, 2006, 02:25:03 AM
what are you talking about?
Title: Re: Cache images page
Post by: Kane on February 04, 2006, 02:39:09 AM
what are you talking about?

From what I understand you can cache the home.html page and the categories.html page but not the details.html. The details.html page is the page where the images reside. Or maybe you can cache that page and I am wrong?
Title: Re: Cache images page
Post by: V@no on February 04, 2006, 04:22:22 AM
Well, yes, your are correct. But, if you think about what the cache feature does, then it actualy has no use on details page, simply because - how many times a visitor will visit same image?

The cache feature saves compilled pages into files and use them next time same visitor opened that page again, instead of compilling the page again. To avoid any security breach, the cached pages are unique for each visitor, that means that one visitor will not see somebody's else cached pages...(guests are exeption)

Because home and categories pages are most intensive (perfomance wise) for the server, they are cached, but details page does not require much server resources, and is much more dynamic then any other pages (each image has its own data to be displayed), that's why its pointless cache it.
Title: Re: Cache images page
Post by: Kane on March 17, 2006, 06:57:29 PM
That's true but my website gets linked by huge sites pretty often and I'll have a couple thousand guest users all visiting the same image. If this page were cached it would help out a lot on my server.
Title: Re: Cache images page
Post by: V@no on March 18, 2006, 12:47:38 AM
Ok, I have not tested this code, so try it on your own risk ;)

in details.php find:
Code: [Select]
$random_cat_image = (defined("SHOW_RANDOM_IMAGE") && SHOW_RANDOM_IMAGE == 0) ? "" : get_random_image($cat_id);
Insert above:
Code: [Select]
$cache_id = create_cache_id(
  'details',
  array(
    $user_info[$user_table_fields['user_id']],
    $image_id,
    $mode,
    isset($user_info['lightbox_image_ids']) ? substr(md5($user_info['lightbox_image_ids']), 0, 8) : 0,
    $config['template_dir'],
    $config['language_dir']
  )
);
if (!$cache_page_categories || !$content = get_cache_file($cache_id)) {
// Always append session id if cache is enabled
if ($cache_page_categories) {
  $old_session_mode = $site_sess->mode;
  $site_sess->mode = 'get';
}

ob_start();


Then find:
Code: [Select]
include(ROOT_PATH.'includes/page_footer.php');
Insert above:
Code: [Select]
$content = ob_get_contents();
ob_end_clean();

if ($cache_page_categories) {
  // Reset session mode
  $site_sess->mode = $old_session_mode;

  save_cache_file($cache_id, $content);
}

} // end if get_cache_file()

echo $content;
Title: Re: Cache images page
Post by: Kane on March 18, 2006, 06:55:55 AM
You're a genius, it worked. Thank you very much.
Title: Re: Cache images page
Post by: IcEcReaM on March 18, 2006, 08:34:34 PM
but if you got a lot of images,
the your cache folder can be get very full of cached pages,
cause the image are also cached, right?

Title: Re: Cache images page
Post by: V@no on March 18, 2006, 10:39:59 PM
actualy this only cache the compilled HTML code of the page ;)
Title: Re: Cache images page
Post by: IcEcReaM on March 18, 2006, 11:45:54 PM
ah, ok i see.

i never used the cache function before,
and thought that the images were also get cached in the compiled html file instead of linking to them.
Title: Re: Cache images page
Post by: Kane on March 19, 2006, 07:15:54 PM
For my gallery I set the cache for four hours, replaced "getimagesize" in function.php with filesize, and now applied this current hack to cache the images page. And now my server load has been reduced by about 70% and pages loads MUCH faster. I'm still looking for more ways to better optimize 4images for large websites (I get over 20,000 visiters daily) but for now it's working great.
Title: Re: Cache images page
Post by: jackald on December 07, 2009, 03:55:46 PM
It works great, but what if I am using mod with big pictures( /big directory for original images)
When i click on image it wont direct you to original image.