Cache Script

Hier können Probleme und alles andere in Deutscher Sprache gelöst werden.
Twins
Regular
Posts: 74
Joined: Wed Dec 21, 2005 5:20 pm
Contact:

Cache Script

Post by Twins »

Ich habe ein Script gefunden, das angeblich cachen soll.

OPEN

serendipity_config.inc.php

FIND

Code: Select all

define('IS_installed', file_exists('serendipity_config_local.inc.php'));

if (IS_installed === true && !defined('IN_serendipity')) {
    define('IN_serendipity', true);
}
AFTER ADD

Code: Select all

include(S9Y_INCLUDE_PATH . 'common/cache.php');
cache.php:

Code: Select all

<?php

define('CACHE_EXIT_ON_FINISH',0);	
define('CACHE_KEY',1);		
define('CACHE_TIME',2);		
define('CACHE_KEY_ENCODING',3);	
define('CACHE_SUFFIX',4);	
define('CACHE_LOC',5);		
define('CACHE_VERBOSE',6);	
define('CACHE_TEST_TIME',7);	
define('CACHE_TEST_CALLBACK',8);	
define('CACHE_FORCE_NOUSAGE',13);
define('CACHE_FORCE_LAST',14);	
define('CACHE_FORCE_REFRESH',15);	
define('CACHE_FORCE_USE',16);	
define('CACHE_WHOLE_PAGE',19);
define('CACHE_PARTIAL_PAGE',20);
$CACHE_DEFAULTS = array(
);
$cache_registry = array();
function cache_zone_start ($options=NULL) {
global $cache_registry;
cache_test_options($options);
if (cache_resolve_option(CACHE_FORCE_REFRESH,$options,false)) {
$use_cache = false;
$save_this = true;
} else if (cache_resolve_option(CACHE_FORCE_USE,$options,false)) {
$use_cache = true;
$save_this = false;
} else if (cache_resolve_option(CACHE_FORCE_NOUSAGE,$options,false)) {
$use_cache = false;
$save_this = false;
} else if (cache_resolve_option(CACHE_FORCE_LAST,$options,false)) {
$use_cache = true;
$save_this = true;
} else {
if (cache_resolve_option(CACHE_TEST_TIME,$options,true)) {
if ($cache_length = cache_resolve_option(CACHE_TIME,$options,(60*60))) {
$uname = cache_resolve_fname($options);
if (file_exists($uname)) {
if (time() - filemtime($uname) < $cache_length) {
$use_cache = true;
$save_this = false;
} else {	
$use_cache = false;
$save_this = true;
}
} else {	
$use_cache = false;
$save_this = true;
}
} else {	
$use_cache = false;
$save_this = true;
}
}
if (!$use_cache && $func = cache_resolve_option(CACHE_TEST_CALLBACK,$options)) {
$use_cache = $func(&$options);	
$save_this = !$use_cache;
}
}
if (!isset($use_cache) || !isset($save_this)) {
$use_cache = false;
$save_this = true;
if (cache_resolve_options(CACHE_VERBOSE,$options)) {
trigger_error('No CACHE_TEST_* or CACHE_FORCE_* method given.',E_WARNING);
}
}
if ($use_cache) { 
if (!isset($uname)) {	
$uname = cache_resolve_fname($options);
}
if (file_exists($uname)) {
include($uname);
if (cache_resolve_option(CACHE_EXIT_ON_FINISH,$options,true)) {
exit;
}
} else {	
$use_cache = false;
$save_this = true;
}
}
ob_start();
$options['using_cache'] = $use_cache;
$options['save_this'] = $save_this;
$cache_registry[] = $options;
return $use_cache;
}
function cache_zone_end() {
global $cache_registry;
$index = count($cache_registry) - 1;
if ($index == -1) {
if (cache_resolve_option(CACHE_VERBOSE,$options)) {
trigger_error("cache_zone_end() called outside of cache zone.",E_WARNING);
}
return -1;
}
$options =& $cache_registry[$index];
if ($options['save_this']) {	
$uname = cache_resolve_fname($options);	
$cachefile = fopen($uname,'w');
$contents = ob_get_contents();
fwrite($cachefile,$contents);
fclose($cachefile);
ob_end_flush(); 
} else if ($options['using_cache']) {
ob_end_clean();
if (cache_resolve_option(CACHE_VERBOSE,$options)) {
trigger_error("cache_zone_end() called when a cache was not used.",E_WARNING);
}
} else { 
ob_end_flush();
}
unset($cache_registry[$index]);	
return $index;
}
function cache_force_refresh($options=NULL) {
cache_test_options($options);
unlink(cache_resolve_fname($options));
}
function cache_set_opt ($option,$value) {
$GLOBALS[$CACHE_DEFAULTS[$option]] = $value;
}
function cache_unset_opt ($option) {
unset($GLOBALS[$CACHE_DEFAULTS[$option]]);
}
function cache_get_opt($option) {
return $GLOBALS[$CACHE_DEFAULTS[$option]];
}
function cache_resolve_fname($options=NULL) {
$key = cache_resolve_option(CACHE_KEY,$options,$REQUEST_URI); 
$encoding = cache_resolve_option(CACHE_KEY_ENCODING,$options,'md5');
if (strlen($encoding) > 0) {
$key = $encoding($key);
}
$uname = cache_resolve_option(CACHE_LOC,$options,'cache/') . $key . cache_resolve_option(CACHE_SUFFIX,$options,'.cache');
return $uname;
}
function cache_resolve_option ($key,$options=NULL,$last_resort=NULL) {
global $CACHE_DEFAULTS;
if (is_array($options) && isset($options[$key])) { 
return $options[$key];
} else if (isset($CACHE_DEFAULTS[$key])) { 
return $CACHE_DEFAULTS[$key];
} else {				
return $last_resort;
}
}
function cache_test_options(&$options) {
if (is_array($options)) {
} else if (is_scalar($options)) {
switch ($options) {
case CACHE_WHOLE_PAGE:
$options = array(
CACHE_EXIT_ON_FINISH => true
);
break;
case CACHE_PARTIAL_PAGE:
$options = array(
CACHE_EXIT_ON_FINISH => false
);
break;
default:
if (cache_resolve_option(CACHE_VERBOSE)) {
trigger_error("Passed unknown option. Ignored.",E_WARNING);
}
}
} else if (!isset($options) || is_null($options) || empty($options)) {
$options = array();	
} else {
trigger_error("Passed an object or resource. What?");
}
}

?>
Bringt mir das überhaupt was? Von einen Geschwindigkeitsanstieg merke ich nämlich nichts.
garvinhicking
Core Developer
Posts: 30022
Joined: Tue Sep 16, 2003 9:45 pm
Location: Cologne, Germany
Contact:

Re: Cache Script

Post by garvinhicking »

Das simplecache plugin von Serendipity funktioniert eigentlich gut; das von Dir genannte Script habe ich mir nicht wirklich angeguckt, kann mir aber nicht vorstellen, dass es sonderlich gut mit Serendipity harmoniert...

Am meisten bringt übrigens die Installation eines PHP Caches wie APC oder eAccelerator.

Grüße,
Garvin
# Garvin Hicking (s9y Developer)
# Did I help you? Consider making me happy: http://wishes.garv.in/
# or use my PayPal account "paypal {at} supergarv (dot) de"
# My "other" hobby: http://flickr.garv.in/
Twins
Regular
Posts: 74
Joined: Wed Dec 21, 2005 5:20 pm
Contact:

Re: Cache Script

Post by Twins »

garvinhicking wrote:Das simplecache plugin von Serendipity
Wie kann ich das aktivieren? Oder ist das schon angeschaltet?

Ich entferne das mal, das bringt nichts. Das treibt nur die Queries in die Höhe, aber ein Performanceanstieg gibt es nicht.
garvinhicking
Core Developer
Posts: 30022
Joined: Tue Sep 16, 2003 9:45 pm
Location: Cologne, Germany
Contact:

Re: Cache Script

Post by garvinhicking »

Hi!
Wie kann ich das aktivieren? Oder ist das schon angeschaltet?
Das ist ein Plugin, was via spartacus verfügbar ist. Muss also erst installiert werden.

Viele Grüße,
Garvin
# Garvin Hicking (s9y Developer)
# Did I help you? Consider making me happy: http://wishes.garv.in/
# or use my PayPal account "paypal {at} supergarv (dot) de"
# My "other" hobby: http://flickr.garv.in/
Twins
Regular
Posts: 74
Joined: Wed Dec 21, 2005 5:20 pm
Contact:

Post by Twins »

Spartacus? Wie genau geht das? Ich weiß, das das ein Plugin ist, aber wie benutzt und aktiviert man das?
garvinhicking
Core Developer
Posts: 30022
Joined: Tue Sep 16, 2003 9:45 pm
Location: Cologne, Germany
Contact:

Post by garvinhicking »

1. Spartacus Event Plugin installieren
2. Nochmal ein neues Event-Plugin installieren, und große Kinderaugen kriegen, weil die Liste der Plugins jetzt viel größer ist :-)

Viele Grüße,
Garvin
# Garvin Hicking (s9y Developer)
# Did I help you? Consider making me happy: http://wishes.garv.in/
# or use my PayPal account "paypal {at} supergarv (dot) de"
# My "other" hobby: http://flickr.garv.in/
Twins
Regular
Posts: 74
Joined: Wed Dec 21, 2005 5:20 pm
Contact:

Post by Twins »

garvinhicking wrote:1. Spartacus Event Plugin installieren
Oh je, da merkt man mal wieder, das ich die FAQ auf der Seite nicht lesen kann, da mein Englisch sehr schlecht ist. Wo bekomme ich das "Spartacus Event Plugin" her? :lol:
Col. Kurtz
Regular
Posts: 450
Joined: Thu May 26, 2005 10:43 am
Location: Bonn, Germany
Contact:

Post by Col. Kurtz »

Indem Du im Plugin-Verwalten Menu auf "neues Eventplugin installieren" klickst, Spartacus auswählst und voila!
Dann kannst Du (via Spartacus) direkt andere Plugins aus dem netz installieren.
Marc
Twins
Regular
Posts: 74
Joined: Wed Dec 21, 2005 5:20 pm
Contact:

Post by Twins »

Ich habe das " Spartacus Event Plugin" jetzt installiert, unw ie geht es jetzt weiter? Ist die Cache jetzt aktiviert oder was muss ich jetzt noch machen?
Oliver
Regular
Posts: 178
Joined: Mon Jan 10, 2005 7:43 pm
Location: Herne, Germany
Contact:

Post by Oliver »

garvinhicking wrote:2. Nochmal ein neues Event-Plugin installieren, und große Kinderaugen kriegen, weil die Liste der Plugins jetzt viel größer ist :-)
Wie Garvin geschrieben hat, jetzt installierst Du nochmal ein Event-/Ereignis-Plugin, die Liste der verfügbaren Plugins hat sich nun vergrößerst und irgendwo da in der Liste gibt es dann auch das Cache-Plugin, das Du dann installieren kannst.

Beachte, daß wenn Du ein Plugin via Spartacus installierst, das ein wenig dauern kann :)
Image
Twins
Regular
Posts: 74
Joined: Wed Dec 21, 2005 5:20 pm
Contact:

Post by Twins »

Ist das "Erweiterte Eigenschaften von Artikeln Plugin" das richtige? Dort kann man nämlich das cachen von Arikelt anstellen. Wenn nein, was ist das richtige? ich bin die komplette Liste durchgegangen und habe nur das oben genannte gefunden.
garvinhicking
Core Developer
Posts: 30022
Joined: Tue Sep 16, 2003 9:45 pm
Location: Cologne, Germany
Contact:

Post by garvinhicking »

Nein, das ist nicht das richtige Plugin. "'Einfache Cached/Pregenerated Seiten" ist das richtige. :-)

Viele Grüße,
Garvin
# Garvin Hicking (s9y Developer)
# Did I help you? Consider making me happy: http://wishes.garv.in/
# or use my PayPal account "paypal {at} supergarv (dot) de"
# My "other" hobby: http://flickr.garv.in/
Twins
Regular
Posts: 74
Joined: Wed Dec 21, 2005 5:20 pm
Contact:

Post by Twins »

Ich habe Spartacus installiert, dann aber dein genanntes Plugin in der Event-Liste nicht finden.
garvinhicking
Core Developer
Posts: 30022
Joined: Tue Sep 16, 2003 9:45 pm
Location: Cologne, Germany
Contact:

Post by garvinhicking »

Welche Plugins hast Du denn in der Liste? mach mal bitte ein paar Screenshots. Auch von deinen installierten Plugins, bitte.

Viele Grüße,
Garvin
# Garvin Hicking (s9y Developer)
# Did I help you? Consider making me happy: http://wishes.garv.in/
# or use my PayPal account "paypal {at} supergarv (dot) de"
# My "other" hobby: http://flickr.garv.in/
Twins
Regular
Posts: 74
Joined: Wed Dec 21, 2005 5:20 pm
Contact:

Post by Twins »

Ich habe die Bilder mal hier als Attachment angehangen, Zip Format (Gäste können sie auch sehen).
Post Reply