Search code examples
phpmemcacheddynamic-function

Storing php function variables in memcached


I was wondering if it is possible to store function variables in memcached. I wrote basic templating system which compiles xml templates into functions. The templates can get very big and I think I could get a performance boost if I could cache it. Would something like this work, or would I just be caching a reference to the function?

$populate_template = function($values){
   //compiled template
};
$memcached_object->set("some_key",$populated_template);

EDIT: I do realize that there are php accelerators that do exactly what I want, however it would be a lot easier to be able to use memcached because I won't have to go through the process of getting another technology approved.


Solution

  • I don't think so. Naturally, I looked at serializing it. But:

    PHP Warning:  Uncaught exception 'Exception' with message 'Serialization of 'Closure' is not allowed' in php shell code:1
    

    With memcached, all you can probably do is store the code as a string, then call create_function after you pull it out.