Experimental project

This is a sandbox project, which contains experimental code for developer use only.

Drupal 7 only.

ONCE THE MODULE IS STARRED FIVE TIMES IT WILL BE RELEASED AS AN OFFICIAL MODULE.

Summary

Set variables without the performance hit of variable_set(). It is comparable with the state values used in Drupal 8, in the sense that it is intended to store transient information, that is okay to lose.

Description

The Drupal variables are cached as one string. But upon calling variable_set() on any page requires this variable cache to be refreshed. This leads to a heavy MySQL query, SELECT * FROM variables. Best practice is to only use this call on administrative tasks. Avoid it on any other page.

If you really need to set values outside the administrative context you can use this module's provided functions (see below). It is intended for use in contrib/custom code.

Concept

The module uses a table {lightvar} that is similar in structure as the core variable table but will remain a lot smaller because of its limited use. Furthermore the module defined functions do not make use of the big cached variable $conf, leaving that unaltered.

Usage

Use instead of:
- variable_set() -> lightvar_set()
- variable_get() -> lightvar_get()
- variable_del() -> lightvar_del()

Example use case

  // Generate a watchdog message only every 100 occurrences instead of each time.
  if (lightvar_get('mycustom_counter', 0) %100 == 0) {
    watchdog('mycustom', 'Warning: $_COOKIE[\'SomeToken\'] is not known for 100 visitors since the last similar warning.', array(), WATCHDOG_ALERT);
    }
  lightvar_set('mycustom_counter', lightvar_get('mycustom_counter', 0) + 1);

Get it

Sandbox projects like this one do not have a download link. To get it you should install git on your system and follow the instructions found in the Version control tab at the top of this page.

Supporting organizations: 
Development time

Project information

  • caution Maintenance fixes only
    Considered feature-complete by its maintainers.
  • Module categories: Performance
  • Created by lolandese on , updated