variable_get() should support a third argument to override caching

clouserw - December 13, 2007 - 19:27
Project:Drupal
Version:7.x-dev
Component:base system
Category:feature request
Priority:normal
Assigned:Unassigned
Status:active
Description

variable_get() employs caching which is useful most of the time but can be detrimental when it's important to guarantee the newest value from the database. Providing a third boolean argument to variable_get() could make it query the database and retrieve the latest value.

(Currently, the only way to get a new value with variable_get() is to clear the entire variable cache with cache_clear_all().)

#1

JirkaRybka - December 13, 2007 - 21:49
Version:5.1» 7.x-dev

This might be also useful for install.php, where a variable needs to be retrieved before matching bootstrap (currently done directly via local implementation of a query).

But otherwise, new features (API-changing like this, especially) should go into 7.x as far as I know.

#2

clouserw - December 15, 2007 - 00:52

Adding an optional third parameter is a pretty small change. We're not talking about objects that can be extended, so we shouldn't be conflicting with any overloaded methods. I'm suggesting the signature be:

function variable_get($name, $default, $cached=true)

which shouldn't break or change any existing code. I'd recommend targeting 6.x-dev (but I'm not as familiar with your versioning, so I'll just leave it at that).

Thanks.

 
 

Drupal is a registered trademark of Dries Buytaert.