Problem/Motivation
Hi,
thank you for your work. However, using views_php 7.x-1.0 a problem occurs using the php-cache.
It didn't appear in 7.x-1.0-alpha3 and I've tested on PHP 7.3.27.
The problem:
Enter any php-code in the php-field ("Caching options") like "return true". You will see that the views-cache will be updated on each reload instead of "never" (what "return true" means).
Steps to reproduce
Create any view. Under advanced => cache select "PHP"
In Result cache code and Output cache code enter return true
Using devel you can see that for each reload the cached data is updated.
OR
in file views_php/plugins/views/views_php_plugin_cache.inc on line 74
add
drupal_set_message('in '.__FUNCTION__.' for '.$type . ' FRESH IS: '.var_export($fresh,1))
You will see that $fresh is always NULL. Which means: "refresh the cache".
Proposed resolution
A simple solution would be to add a "return" before each "eval" in the function cache_get($type).
Or maybe stick with the old $function = create_function('$view, $plugin, $cache', $this->options['php_cache_results'] . ';');
I don't know, which is better. But eval sounds more evil ;-)
Remaining tasks
fix php-cache
User interface changes
none
API changes
none
Data model changes
none
| Comment | File | Size | Author |
|---|---|---|---|
| #9 | views_php_7.1_cache_fix.diff | 1.15 KB | Bernhard Strehl |
Comments
Comment #2
Bernhard Strehl commentedonly formatting
Comment #3
Bernhard Strehl commentedonly formatting
Comment #4
avpadernoComment #5
liam morlandcreate_function() is deprecated and was removed in #2274543: [7.x-1.x] Remove usage of deprecated create_function(). If it worked in a previous version, what commit caused it to break?
Comment #6
avpadernoI am not sure this explains why the cache is emptied, but on #2274543: [7.x-1.x] Remove usage of deprecated create_function() comment #52 says:
Comment #7
Bernhard Strehl commentedThis is still an issue in views_php 7.x-1.1 ....
The variable $fresh is still null thus the cache is considered to be "old/not fresh".
Thus the view gets re-rendered and re-cached.
Comment #8
Bernhard Strehl commentedWhoever is interested: I attached a temporary fix to adress this problem.
Comment #9
Bernhard Strehl commentedSorry, fix in #8 is broken.
Again: Whoever is interested: I attached a temporary fix to adress this problem.