4

I use some php library, and generate element of class

 $elnew = new LibClass(); 

I want to save this variable to cache. If I make like this

$elem = $cache->getItem($ig_name); if (!$elem->isHit()) { $elem->set($elnew); $cache->save($ig); } 

$elem->isHit() is always false. I checked how cache works with string - all is ok. Also I'm not able to serialyze/unserialyze this object because it says

Serialization of 'Closure' is not allowed

and no way to modify LibClass

How can I save $elnew to cache? Any variants for with symfony components? Or maybe other libs can help me?

1 Answer 1

1

Serialization of 'Closure' is not allowed

You can use the PHP SuperClosure library to get rid of this.

Also you can try other memory storages like Redis or Memcache to cache your objects. See this resolved stackoverflow question.

Sign up to request clarification or add additional context in comments.

3 Comments

You are right about the SuperClousure, but be careful about its restrictions. And only to be clear: Redis and Memcache aren't libraries, they are external in-memory storages. Symfony Cache already supports them and many others.
@Timurib yes my bad they aren't libraries. But Symfony cache does not support closure serialization that's why I proposed them.
I try this lib and some similar. They don't work in my variant, they don't like that my object is really class instance

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.