mirror of
https://github.com/moodle/moodle.git
synced 2025-08-08 02:16:41 +02:00
rcache: cleanup, upgrade path, config options (MDL-8163)
record cache and caching schemes get a little cleanup, faster if()s and a nice set of config options. Users who've been using the internal cache get a nice upgrade too.
This commit is contained in:
parent
a5855a89bf
commit
bb931a61c6
5 changed files with 77 additions and 17 deletions
|
@ -510,6 +510,20 @@ function xmldb_main_upgrade($oldversion=0) {
|
|||
/// use get record set to iterate slower
|
||||
build_context_rel();
|
||||
}
|
||||
|
||||
if ($result && $oldversion < 2007011501) {
|
||||
if (!empty($CFG->enablerecordcache) && empty($CFG->rcache) &&
|
||||
// Note: won't force-load these settings into CFG
|
||||
// we don't need or want cache during the upgrade itself
|
||||
empty($CFG->cachetype) && empty($CFG->intcachemax)) {
|
||||
set_config('cachetype', 'internal');
|
||||
set_config('rcache', true);
|
||||
set_config('intcachemax', $CFG->enablerecordcache);
|
||||
unset_config('enablerecordcache');
|
||||
unset($CFG->enablerecordcache);
|
||||
}
|
||||
}
|
||||
|
||||
return $result;
|
||||
|
||||
}
|
||||
|
|
|
@ -386,7 +386,7 @@ function get_record($table, $field1, $value1, $field2='', $value2='', $field3=''
|
|||
|
||||
// Check to see whether this record is eligible for caching (fields=*, only condition is id)
|
||||
$docache = false;
|
||||
if (!empty($CFG->rcache) && $field1=='id' && !$field2 && !$field3 && $fields=='*') {
|
||||
if ($CFG->rcache === true && $field1=='id' && !$field2 && !$field3 && $fields=='*') {
|
||||
$docache = true;
|
||||
// If it's in the cache, return it
|
||||
$cached = rcache_getforfill($table, $value1);
|
||||
|
@ -1044,7 +1044,7 @@ function set_field($table, $newfield, $newvalue, $field1, $value1, $field2='', $
|
|||
|
||||
// Clear record_cache based on the parameters passed
|
||||
// (individual record or whole table)
|
||||
if (!empty($CFG->rcache)) {
|
||||
if ($CFG->rcache === true) {
|
||||
if ($field1 == 'id') {
|
||||
rcache_unset($table, $value1);
|
||||
} else if ($field2 == 'id') {
|
||||
|
@ -1086,7 +1086,7 @@ function set_field_select($table, $newfield, $newvalue, $select, $localcall = fa
|
|||
|
||||
// Clear record_cache based on the parameters passed
|
||||
// (individual record or whole table)
|
||||
if (!empty($CFG->rcache)) {
|
||||
if ($CFG->rcache === true) {
|
||||
rcache_unset_table($table);
|
||||
}
|
||||
}
|
||||
|
@ -1145,7 +1145,7 @@ function delete_records($table, $field1='', $value1='', $field2='', $value2='',
|
|||
|
||||
// Clear record_cache based on the parameters passed
|
||||
// (individual record or whole table)
|
||||
if (!empty($CFG->rcache)) {
|
||||
if ($CFG->rcache === true) {
|
||||
if ($field1 == 'id') {
|
||||
rcache_unset($table, $value1);
|
||||
} else if ($field2 == 'id') {
|
||||
|
@ -1179,7 +1179,7 @@ function delete_records_select($table, $select='') {
|
|||
global $CFG, $db;
|
||||
|
||||
// Clear record_cache (whole table)
|
||||
if (!empty($CFG->rcache)) {
|
||||
if ($CFG->rcache === true) {
|
||||
rcache_unset_table($table);
|
||||
}
|
||||
|
||||
|
@ -1393,7 +1393,7 @@ function update_record($table, $dataobject) {
|
|||
}
|
||||
|
||||
// Remove this record from record cache since it will change
|
||||
if (!empty($CFG->rcache)) {
|
||||
if ($CFG->rcache === true) {
|
||||
rcache_unset($table, $dataobject->id);
|
||||
}
|
||||
|
||||
|
@ -2080,7 +2080,7 @@ function db_update_lobs ($table, $sqlcondition, &$clobs, &$blobs) {
|
|||
function rcache_set($table, $id, $rec) {
|
||||
global $CFG, $MCACHE, $rcache;
|
||||
|
||||
if ($CFG->rcache === 'internal') {
|
||||
if ($CFG->cachetype === 'internal') {
|
||||
$rcache->data[$table][$id] = $rec;
|
||||
} else {
|
||||
$key = $table . '|' . $id;
|
||||
|
@ -2112,7 +2112,7 @@ function rcache_set($table, $id, $rec) {
|
|||
function rcache_unset($table, $id) {
|
||||
global $CFG, $MCACHE, $rcache;
|
||||
|
||||
if ($CFG->rcache === 'internal') {
|
||||
if ($CFG->cachetype === 'internal') {
|
||||
if (isset($rcache->data[$table][$id])) {
|
||||
unset($rcache->data[$table][$id]);
|
||||
}
|
||||
|
@ -2142,7 +2142,7 @@ function rcache_unset($table, $id) {
|
|||
function rcache_get($table, $id) {
|
||||
global $CFG, $MCACHE, $rcache;
|
||||
|
||||
if ($CFG->rcache === 'internal') {
|
||||
if ($CFG->cachetype === 'internal') {
|
||||
if (isset($rcache->data[$table][$id])) {
|
||||
$rcache->hits++;
|
||||
return $rcache->data[$table][$id];
|
||||
|
@ -2197,7 +2197,7 @@ function rcache_get($table, $id) {
|
|||
function rcache_getforfill($table, $id) {
|
||||
global $CFG, $MCACHE, $rcache;
|
||||
|
||||
if ($CFG->rcache === 'internal') {
|
||||
if ($CFG->cachetype === 'internal') {
|
||||
return rcache_get($table, $id);
|
||||
}
|
||||
|
||||
|
@ -2254,7 +2254,7 @@ function rcache_releaseforfill($table, $id) {
|
|||
function rcache_unset_table ($table) {
|
||||
global $CFG, $MCACHE, $rcache;
|
||||
|
||||
if ($CFG->rcache === 'internal') {
|
||||
if ($CFG->cachetype === 'internal') {
|
||||
if (isset($rcache->data[$table])) {
|
||||
unset($rcache->data[$table]);
|
||||
}
|
||||
|
|
|
@ -207,6 +207,7 @@ global $HTTPSPAGEREQUIRED;
|
|||
configure_dbconnection();
|
||||
|
||||
/// Load up any configuration from the config table
|
||||
$CFG->rcache = false;
|
||||
$CFG = get_config();
|
||||
|
||||
/// Turn on SQL logging if required
|
||||
|
@ -267,11 +268,25 @@ global $HTTPSPAGEREQUIRED;
|
|||
/// Shared-Memory cache init -- will set $MCACHE
|
||||
/// $MCACHE is a global object that offers at least add(), set() and delete()
|
||||
/// with similar semantics to the memcached PHP API http://php.net/memcache
|
||||
if (!empty($CFG->memcached) && !empty($CFG->memcachedhosts)) {
|
||||
init_memcached();
|
||||
if (!empty($CFG->cachetype)) {
|
||||
if ($CFG->cachetype === 'memcached' && !empty($CFG->memcachedhosts)) {
|
||||
if (!init_memcached()) {
|
||||
debugging("Error initialising memcached");
|
||||
}
|
||||
} elseif ($CFG->cachetype === 'eaccelerator') {
|
||||
if (!init_eaccelerator()) {
|
||||
debugging("Error initialising eaccelerator cache");
|
||||
}
|
||||
}
|
||||
} else { // just make sure it is defined
|
||||
$CFG->cachetype = '';
|
||||
}
|
||||
if (!empty($CFG->eaccelerator)) {
|
||||
init_eaccelerator();
|
||||
/// Ensure we define rcache - so we can later check for it
|
||||
/// with a really fast and unambiguous $CFG->rcache === false
|
||||
if (empty($CFG->rcache)) {
|
||||
$CFG->rcache = false;
|
||||
} else {
|
||||
$CFG->rcache = true;
|
||||
}
|
||||
|
||||
/// Set a default enrolment configuration (see bug 1598)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue