Commit 831816ab authored by Steve Rude's avatar Steve Rude

* Sync with DRUPAL-5

* Update INSTALLATION.txt and README.txt
parent 568b637a
// $Id$
For instructions on how to compile memcached on Debian Etch, see here:
http://www.lullabot.com/articles/how_install_memcache_debian_etch
Fedora memcache + drupal walkthrough
1) Have a look at the background reading
A - http://www.danga.com/memcached/ (cache daemon)
B - http://pecl.php.net/package/memcache (PHP integration for memcache)
......@@ -26,13 +32,13 @@ Fedora memcache + drupal walkthrough
1010 yum install php-devel
1011 rpmbuild --rebuild php-pecl-memcache-2.0.4-1.rf.src.rpm
3) Installed RPMS
3) Installed RPMS
[root@yoursite ~]# rpm -Uvh /usr/src/redhat/RPMS/x86_64/memcached-1.2.1-4.rf.x86_64.rpm /usr/src/redhat/RPMS/x86_64/php-pecl-memcache-2.0.4-1.rf.x86_64.rpm
Preparing... ########################################### [100%]
1:php-pecl-memcache ########################################### [ 50%]
2:memcached ########################################### [100%]
[root@yoursite ~]#
[root@yoursite ~]#
4) Verify configuration. Change if required.
......@@ -51,7 +57,7 @@ Starting Distributed memory caching (memcached): [ OK ]
[root@yoursite ~]# service httpd restart
Stopping httpd: [ OK ]
Starting httpd: [ OK ]
[root@yoursite ~]#
[root@yoursite ~]#
Check phpinfo() for memcached status. Mine said
......@@ -83,9 +89,17 @@ whole $cfg. The example below uses the default localhost:11211 server.
[simon@yoursite memcache]$ tail -3 ../../sites/default/settings.php
$conf = array(
'memcache_inc' => './includes/memcache.inc',
'cache_inc' => './sites/all/modules/memcache/memcache.inc',
);
[simon@yoursite memcache]$
[simon@yoursite memcache]$
8) Enable the drupal module from /admin/build/modules (it's in the "Other"
section)
section) Note that the memcache module only provides some debug output for
administrators to help you see what memcache is doing. It is non-essential
to the functioning of your site, and can be turned off on a production site.
It is, however, *vital* that you enable the module at least once because it runs
hook_install and adds the serialized column to all of your cache tables.
9) Also see the memcache_admin module (distributed with this package) to monitor
memcache statistics.
......@@ -5,8 +5,8 @@
These are the broad steps you need to take in order to use this software. Order
is important.
1. Install the memcached binaries on your server.
2. Install the PECL memcache extension for PHP.
1. Install the memcached binaries on your server. See http://www.lullabot.com/articles/how_install_memcache_debian_etch
2. Install the PECL memcache extension for PHP. This must be version 2.2.1 or higher or you will experience errors.
3. Put your site into offline mode.
4. Download and install the memcache module.
5. If you have previously been running the memcache module, run update.php.
......@@ -16,9 +16,9 @@ is important.
7. Start at least one instance of memcached on your server.
8. Edit settings.php to configure the servers, clusters and bins that memcache
is supposed to use.
9. Edit settings.php to include either memcache.inc or memcache.db.inc.
10. Optionally, edit settings.php to include memcache-session.inc
11. Bring your site back online.
9. Edit settings.php to include either memcache.inc or memcache.db.inc. For
example, $conf['cache_inc'] ='sites/all/modules/memcache/memcache.db.inc';
10. Bring your site back online.
For instructions on 1 and 2 above, please see the INSTALLATION.txt file that
comes with the memcache module download.
......@@ -89,9 +89,12 @@ or the 11211 instance. The page cache will be in 11212.
$conf = array(
...
// Important to define a default cluster in both the servers
// and in the bins. This links them together.
'memcache_servers' => array('localhost:11211' => 'default',
'localhost:11212' => 'pages'),
'memcache_bins' => array('cache_page' => 'pages'),
'memcache_bins' => array('cache' => 'default',
'cache_page' => 'pages'),
);
Here is an example configuration that has two clusters, 'default' and
......@@ -112,11 +115,11 @@ $conf = array(
'cache_menu' => 'cluster2'),
);
## PREFIXING ##
If you want to have multiple Drupal installations share memcached instances,
you need to include a unique prefix for each Drupal installation in the $conf
array of settings.php:
$conf = array(
...
'memcache_key_prefix' => 'something_unique',
......@@ -159,6 +162,13 @@ cached menu and what the patched code is expecting. Clear cache_menu:
mysql> TRUNCATE cache_menu;
Query OK, 0 rows affected (0.33 sec)
PROBLEM:
Error:
Failed to set key: Failed to set key: cache_page-......
SOLUTION:
Upgrade your PECL library to PECL package (2.2.1) (or higher).
## MEMCACHE ADMIN ##
A module offering a UI for memcache is on the way. It will provide stats, a
......
......@@ -116,11 +116,13 @@ function cache_get($key, $table = 'cache') {
* to memcache.
*/
function cache_set($cid, $table = 'cache', $data, $expire = CACHE_PERMANENT, $headers = NULL, $db_storage = TRUE) {
$time = time();
// Create new cache object.
$cache = new stdClass;
$cache->cid = $cid;
$cache->data = $data;
$cache->created = time();
$cache->data = is_object($data) ? memcache_clone($data) : $data;
$cache->created = $time;
$cache->expire = $expire;
$cache->headers = $headers;
......@@ -134,19 +136,15 @@ function cache_set($cid, $table = 'cache', $data, $expire = CACHE_PERMANENT, $he
db_query("
INSERT INTO {$table} (data, created, expire, headers, serialized, cid) VALUES (%b, %d, %d, '%s', %d, '%s') ON DUPLICATE KEY
UPDATE data = %b, created = %d, expire = %d, headers = '%s', serialized = %d",
$data, time(), $expire, $headers, $serialized, $cid,
$data, time(), $expire, $headers, $serialized);
$data, $time, $expire, $headers, $serialized, $cid,
$data, $time, $expire, $headers, $serialized, $cid);
}
// Save to memcache
if ($expire == CACHE_PERMANENT || $expire > time()) {
dmemcache_set($cid, $cache, $expire, $table);
}
else if ($expire == CACHE_TEMPORARY) {
// A compromise for CACHE_TEMPORARY: Cache for three minutes.
dmemcache_set($cid, $cache, 180, $table);
if ($expire == CACHE_TEMPORARY) {
$expire = variable_get('cache_lifetime', 2591999);
}
dmemcache_set($cid, $cache, $expire, $table);
}
/**
......@@ -170,10 +168,10 @@ function cache_set($cid, $table = 'cache', $data, $expire = CACHE_PERMANENT, $he
function cache_clear_all($cid = NULL, $table = NULL, $wildcard = FALSE) {
global $user;
$bin = empty($table) ? 'cache' : $table;
// Memcache logic is simpler because memcache doesn't have a minimum cache
// lifetime consideration (it handles it internally), and doesn't support
// wildcards.
$bin = empty($table) ? 'cache' : $table;
if (empty($cid) || ($cid == '*' && $wildcard !== TRUE)) {
# don't do anything if cid is unset. this matches the default drupal behavior...
if ($wildcard && $cid != '*') {
......@@ -234,3 +232,12 @@ function cache_clear_all($cid = NULL, $table = NULL, $wildcard = FALSE) {
}
}
}
/**
* Provide a substitute clone() function for PHP4. This is a copy of drupal_clone
* because common.inc isn't included early enough in the bootstrap process to
* be able to depend on drupal_clone.
*/
function memcache_clone($object) {
return version_compare(phpversion(), '5.0') < 0 ? $object : clone($object);
}
......@@ -44,22 +44,21 @@ function cache_get($key, $table = 'cache') {
* to memcache.
*/
function cache_set($cid, $table = 'cache', $data, $expire = CACHE_PERMANENT, $headers = NULL) {
$time = time();
// Create new cache object.
$cache = new stdClass;
$cache->cid = $cid;
$cache->data = is_object($data) ? memcache_clone($data) : $data;
$cache->created = time();
$cache->created = $time;
$cache->expire = $expire;
$cache->headers = $headers;
// Save to memcache
if ($expire == CACHE_PERMANENT || $expire > time()) {
dmemcache_set($cid, $cache, $expire, $table);
}
else if ($expire == CACHE_TEMPORARY) {
// A compromise for CACHE_TEMPORARY: Cache for three minutes.
dmemcache_set($cid, $cache, 180, $table);
if ($expire == CACHE_TEMPORARY) {
$expire = variable_get('cache_lifetime', 2591999);
}
dmemcache_set($cid, $cache, $expire, $table);
}
/**
......@@ -86,7 +85,7 @@ function cache_clear_all($cid = NULL, $table = NULL, $wildcard = FALSE) {
// wildcards.
$bin = empty($table) ? 'cache' : $table;
if (empty($cid) || ($cid == '*' && $wildcard !== TRUE)) {
# don't do anything if cid is unset. this matches the default drupal behavior...
// don't do anything if cid is unset. this matches the default drupal behavior...
if ($wildcard && $cid != '*') {
if (variable_get('memcache_debug', FALSE)) {
// call watchdog, since you probably didn't want to flush the entire bin.
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment