Author Topic: Cache images page  (Read 12992 times)

0 Members and 1 Guest are viewing this topic.

Offline Kane

  • Newbie
  • *
  • Posts: 23
    • View Profile
Cache images page
« 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.

Offline V@no

  • If you don't tell me what to do, I won't tell you where you should go :)
  • Global Moderator
  • 4images Guru
  • *****
  • Posts: 17.849
  • mmm PHP...
    • View Profile
    • 4images MODs Demo
Re: Cache images page
« Reply #1 on: February 03, 2006, 02:25:03 AM »
what are you talking about?
Your first three "must do" before you ask a question:
Please do not PM me asking for help unless you've been specifically asked to do so. Such PMs will be deleted without answer. (forum rule #6)
Extension for Firefox/Thunderbird: Master Password+    Back/Forward History Tweaks (restartless)    Cookies Manager+    Fit Images (restartless for Thunderbird)

Offline Kane

  • Newbie
  • *
  • Posts: 23
    • View Profile
Re: Cache images page
« Reply #2 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?

Offline V@no

  • If you don't tell me what to do, I won't tell you where you should go :)
  • Global Moderator
  • 4images Guru
  • *****
  • Posts: 17.849
  • mmm PHP...
    • View Profile
    • 4images MODs Demo
Re: Cache images page
« Reply #3 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.
Your first three "must do" before you ask a question:
Please do not PM me asking for help unless you've been specifically asked to do so. Such PMs will be deleted without answer. (forum rule #6)
Extension for Firefox/Thunderbird: Master Password+    Back/Forward History Tweaks (restartless)    Cookies Manager+    Fit Images (restartless for Thunderbird)

Offline Kane

  • Newbie
  • *
  • Posts: 23
    • View Profile
Re: Cache images page
« Reply #4 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.

Offline V@no

  • If you don't tell me what to do, I won't tell you where you should go :)
  • Global Moderator
  • 4images Guru
  • *****
  • Posts: 17.849
  • mmm PHP...
    • View Profile
    • 4images MODs Demo
Re: Cache images page
« Reply #5 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;
Your first three "must do" before you ask a question:
Please do not PM me asking for help unless you've been specifically asked to do so. Such PMs will be deleted without answer. (forum rule #6)
Extension for Firefox/Thunderbird: Master Password+    Back/Forward History Tweaks (restartless)    Cookies Manager+    Fit Images (restartless for Thunderbird)

Offline Kane

  • Newbie
  • *
  • Posts: 23
    • View Profile
Re: Cache images page
« Reply #6 on: March 18, 2006, 06:55:55 AM »
You're a genius, it worked. Thank you very much.

Offline IcEcReaM

  • Hero Member
  • *****
  • Posts: 714
    • View Profile
    • My little Testboard
Re: Cache images page
« Reply #7 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?

Coding is a everlasting competition between programmers who tries to write larger, better and idiot-safe programs and the universe producing larger and stupider idiots...
...so far the universe won
bump

Offline V@no

  • If you don't tell me what to do, I won't tell you where you should go :)
  • Global Moderator
  • 4images Guru
  • *****
  • Posts: 17.849
  • mmm PHP...
    • View Profile
    • 4images MODs Demo
Re: Cache images page
« Reply #8 on: March 18, 2006, 10:39:59 PM »
actualy this only cache the compilled HTML code of the page ;)
Your first three "must do" before you ask a question:
Please do not PM me asking for help unless you've been specifically asked to do so. Such PMs will be deleted without answer. (forum rule #6)
Extension for Firefox/Thunderbird: Master Password+    Back/Forward History Tweaks (restartless)    Cookies Manager+    Fit Images (restartless for Thunderbird)

Offline IcEcReaM

  • Hero Member
  • *****
  • Posts: 714
    • View Profile
    • My little Testboard
Re: Cache images page
« Reply #9 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.
Coding is a everlasting competition between programmers who tries to write larger, better and idiot-safe programs and the universe producing larger and stupider idiots...
...so far the universe won
bump

Offline Kane

  • Newbie
  • *
  • Posts: 23
    • View Profile
Re: Cache images page
« Reply #10 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.

Offline jackald

  • Newbie
  • *
  • Posts: 41
    • View Profile
Re: Cache images page
« Reply #11 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.