1

I'm having a problem with views and caching. Within a custom module, i do changes on my database, which is working fine, but my view won't show that changes until I clear all caches.

I tried to deactivate views-caching here "admin/structure/views/settings/advanced" Caching in the view is deactivated too And the whole caching is deactivated here "admin/config/development/performance"

But I still have to clear all caches on every change I make to see what I did. Is there a chance to stop caching for that view by code in the module? Or any other possibility?

EDIT: I now tried a module called "CacheExclude" and

$GLOBALS['conf']['cache'] = 0;
drupal_page_is_cacheable(FALSE);
$conf['cache'] = FALSE;

but no change :(

EDIT 2: Here is the code where I change the field in the database:

foreach($books as $book) {
    $query = db_update('field_data_field_zuordnung')
        ->fields(array(
            'field_zuordnung_value' => 'verkauft',
            ))
        ->condition('entity_id', $book->product_id, '=')
        ->execute();
}

The change is done in the DB, but it isn't shown in the view. After that, I use drupal_goto to move to a "you're done site".

  • You might want to give a bit more detail of what your module does so we can maybe thing of other reasons you are facing the problem. – 2pha Jul 21 '14 at 15:32
  • I am changing a custom field. In the first place I have a variable in that field, after my action, this variable changes. But this change is only visible after I clear my cache. I'm putting some code into the question. – Andi Jul 22 '14 at 8:43
1

You should ideally be using the Field Attach API to avoid these problems.

Or for a quick solution have a look at field_attach_update where at the end of the function, it clears the field cache:

$entity_info = entity_get_info($entity_type);
if ($entity_info['field cache']) {
  cache_clear_all("field:$entity_type:$id", 'cache_field');
}
  • +1 If you don't use the API then relevant hooks won't be invoked which might break functionality provided by other modules (now or in the future). – Andy Jul 22 '14 at 10:43

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.