Update atime inside advagg_aggregates_versions and cache_advagg_info.

Paramètres

array $files: List of files in the aggregate as well as the aggregate name.

Return value

bool Return TRUE if anything was written to the database.

2 calls to advagg_multi_update_atime()
advagg_build_aggregate_plans dans ./advagg.inc
Replacement for drupal_build_css_cache() and drupal_build_js_cache().
advagg_missing_create_file dans ./advagg.missing.inc
Given a filename create that file.

Fichier

./advagg.module, line 3898

Code

function advagg_multi_update_atime(array $files) {
    $write_done = FALSE;
    $records = array();
    foreach ($files as $values) {
        // Create the cache id.
        $cid = 'advagg:db:' . $values['aggregate_filenames_hash'] . ADVAGG_SPACE . $values['aggregate_contents_hash'];
        // Create the db record.
        $records[$cid] = array(
            'aggregate_filenames_hash' => $values['aggregate_filenames_hash'],
            'aggregate_contents_hash' => $values['aggregate_contents_hash'],
            'atime' => REQUEST_TIME,
        );
    }
    // Use the cache.
    $cids = array_keys($records);
    $caches = cache_get_multiple($cids, 'cache_advagg_info');
    if (!empty($caches)) {
        foreach ($caches as $cache) {
            // See if the atime value needs to be updated.
            if (!empty($cache->data['atime']) && $cache->data['atime'] > REQUEST_TIME - 12 * 60 * 60) {
                // If atime is less than 12 hours old, do nothing.
                unset($records[$cache->cid]);
            }
        }
    }
    if (empty($records)) {
        return $write_done;
    }
    foreach ($records as $cid => $record) {
        // Update atime in DB.
        $result = db_merge('advagg_aggregates_versions')->key(array(
            'aggregate_filenames_hash' => $record['aggregate_filenames_hash'],
            'aggregate_contents_hash' => $record['aggregate_contents_hash'],
        ))
            ->fields(array(
            'atime' => $record['atime'],
        ))
            ->execute();
        if (!$write_done && $result) {
            $write_done = TRUE;
        }
        // Update the atime in the cache.
        // Get fresh copy of the cache.
        $cache = cache_get($cid, 'cache_advagg_info');
        // Set the atime.
        if (empty($cache->data)) {
            $cache = new stdClass();
        }
        $cache->data['atime'] = REQUEST_TIME;
        // Write to the cache.
        // CACHE_PERMANENT isn't good here. Use 2 weeks from now + 0-45 days.
        // The random 0 to 45 day addition is to prevent a cache stampede.
        cache_set($cid, $cache->data, 'cache_advagg_info', round(REQUEST_TIME + 1209600 + mt_rand(0, 3888000), -3));
    }
    return $write_done;
}