Summary of the problem

Currently all nodes (technically all objects of a given entity type) have to share the same class for determining their expiry types. While this class can be defined by the variable expire_handler_node etc you can't have for example one class for clearing forums and another for clearing book pages.

You can write a function which uses the hook expire_cache_alter which checks for the node type and perform custom logic but this does not get information on the action. It is likely that you may want to clear items differently depending on weather an item was inserted or updated (A listing page will need wildcard on insert to keep pagination consistent, but will only need one page cleared on an update) It would also seem better stylistically to define clearing rules in a custom class rather than doing a lot of work in an alter hook.

Proposed Solution

When _expire_get_expiration_handler is called it should also be passed the object type (if it is defined), and it could check for variables specific to the type before falling back to the generic entity type class.

Something like:

function_expire_get_expiration_handler($type, $obj_type = NULL) {
  static $cache_objects; // NOTE this should be drupal_static in D7!
  if ($obj_type != NULL) {
    if (!isset($cache_objects[$type . $obj_type]) {
         $class=variable_get('expire_handler_' . $type,'Expire' . drupal_ucfirst($type) . '_' . drupal_ucfirst($obj_type));
         if ($class) {
           $cache_objects[$type . $obj_type] = new $class();
           return $cache_objects[$type . $obj_type];
         }
     }
     else {
       return $cache_objects[$type . $obj_type];

     }
  }

if(!isset($cache_objects[$type])) {
$class=variable_get('expire_handler_' . $type,'Expire' . drupal_ucfirst($type));
$cache_objects[$type] = new $class();
  }
return$cache_objects[$type];
}

This would allow more granular definition of cash clearing logic, as well as allowing a module which defines a content type to also define a class for clearing items of the content type.

If people like the proposed solution or at least have no objections I'll try rolling a patch.

Comments

Spleshka’s picture

Status: Active » Needs work

Hey,

Good idea. I'd gladly apply a patch for that. Please, provide full implementation of your idea.

JeremyFrench’s picture

Assigned: Unassigned » JeremyFrench
Spleshka’s picture

Status: Needs work » Postponed

Any progress here? Postpone this issue because of no progress.