Path

ez projects / ezjscore / forum / general / is getcachetime working ?


is getCacheTime working ?

You need to be logged in to post messages in the forums. New users may register here.

Jerome Despatis

Member since:
11 November 2008

Posts: 20

Thursday 27 January 2011 7:03:01 pm

Hi

I've created function that extends ezjscServerFunctions in order to generate some js/css on the fly. But I don't want the result to be cached

I've seen the method getCacheTime( $functionName ), seems to be designed for this, however it doesn't seem to work.
In fact I can read on http://projects.ez.no/ezjscore, in the TODO section:
* template handlers does not let you specify expiry time like static files (modified time) and php handlers do ( ::getCacheTime )

but not sure this information is up to date, any idea ?

You'll find below a simple code for testing:
If I comment the getCacheTime block, the js shows an alert on the time (but always the same time because of cache)
And if I uncomment it, then The js code is not inserted at all in the global .js file..

Any idea is welcome !




class dmvServerFunctions extends ezjscServerFunctions


{


   public static function getCacheTime( $functionName )


   {


       return -1;


   }


 

   public static function dojo_load( $args )


   {


       $time = time();


       return "alert('time is: $time');";


   }


}



Up

Jerome Despatis

Member since:
11 November 2008

Posts: 20

Thursday 27 January 2011 7:14:57 pm

Well It seems to be a bug, I've filled in a report:
http://issues.ez.no/IssueView.php?Id=17892

The fact is, when using getCacheTime, I get the warning:

file_get_contents(alert('time is: 1296151486');) [<a href='function.file-get-contents'>function.file-get-contents</a>]: failed to open stream: No such file or directory in /.../ezpublish-4.4.0-gpl/extension/ezjscore/classes/ezjscpacker.php on line 419
Up

André R.

Member since:
14 January 2008

Posts: 170

Friday 28 January 2011 3:13:22 pm

-1 is special case, it's used for dynamic calls like ::yui3 that don't actually generate any content them self, but manipulates the array of included files dynamically.

If you want it to always invalidate, then you could use "return time();". But then it will cache the file to disk and update it on every call, not efficient. So best (if you have to use ezjscore for this, might be creating a template operator for this case is better then use a js packer and ask it to not cache it is a bit indirect approach :) ) is probably to use ezscript('my::function',,,,0) to disable packing for this specific call so it is included inline in the html.

Lead Engineer eZ Publish
@: http://twitter.com/andrerom

Up

Jerome Despatis

Member since:
11 November 2008

Posts: 20

Monday 21 February 2011 11:49:55 am

Oups, I've missed your answer, thanks for it André.

I see for the -1 => I invalid the bug issue

your code is exactly what I need indeed, cool !

The fact is I could code a template operator yes, but I prefer to put all my css/js generation in the same class, in ezjscore_server

packer=0 is perfect for my need, didn't know that...
Up

You need to be logged in to post messages in the forums. New users may register here.