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

Comments

Bernhard Strehl created an issue. See original summary.

Bernhard Strehl’s picture

Issue summary: View changes

only formatting

Bernhard Strehl’s picture

Issue summary: View changes

only formatting

avpaderno’s picture

Version: 7.x-1.0 » 7.x-1.x-dev
liam morland’s picture

create_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?

avpaderno’s picture

I 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:

eval() created functions are anonymous functions that are implemented using the Closure class and thus cannot be serialized for the purpose of caching.

Bernhard Strehl’s picture

This 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.

Bernhard Strehl’s picture

StatusFileSize
new1.15 KB

Whoever is interested: I attached a temporary fix to adress this problem.

Bernhard Strehl’s picture

StatusFileSize
new1.15 KB

Sorry, fix in #8 is broken.
Again: Whoever is interested: I attached a temporary fix to adress this problem.