M
M
mihelsonkk2015-11-05 11:04:21
PHP
mihelsonkk, 2015-11-05 11:04:21

Proper storage of objects in php?

I want to cache the results of the work of a heavy class. but it is not clear how to correctly store a frequently used object (returned from a class method) in the cache (file cache, that is, I would like to save the object in a string). tried serialization, but in object protection.

public function __wakeup() {
        trigger_error('Unserializing is not allowed.', E_USER_ERROR);
    }

removed the trigger - naturally, php saved the object crookedly,
what other options are there?
php 5.5.23

Answer the question

In order to leave comments, you need to log in

2 answer(s)
M
mihelsonkk, 2015-11-05
@mihelsonkk

Resolved (case, not object storage in php) Firstly, I realized that storing the entire object is expensive. It's easier to write a wrapper for the data you really need and store it, for example, in an array. Secondly, having carefully studied the object again, I found the methods already implemented there for serialization (json).
How to store objects is now more academic than practical interest.

D
Denis, 2015-11-05
@prototype_denis

https://github.com/doctrine/cache/tree/master/lib/...

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question