Cache Object in PHP without using serialize

后端 未结 9 995
眼角桃花
眼角桃花 2020-12-14 12:26

I have a complex object that I create in a PHP script. I am looking for a way to store this object such that subsequent requests do not have to recreate it, or spend time un

9条回答
  •  南方客
    南方客 (楼主)
    2020-12-14 12:50

    NO, it is not possible to store a PHP object in a non-serialized form ; at least, not with the following caching solutions (I've tried these ones ; don't know about the other that might exist) :

    • files
    • memcached
    • APC
    • Database (yeap, you can think about caching things in DB ^^ Drupal does it by default, for instance )

    If it takes that much time to unserialize your object, maybe it is really big ? Is there any way you could reduce it's size ?

    For instance, meybe you have a big bunch of HTML code in that object ? If so, could it be stored in another cache entry ?
    (serialization is "transforming some data to a string ; so, if you are already working with a string, you don't need to re-serialize it to store it in cache)

    Or maybe it doesn't take much time to create it from scratch ? In this case, is caching really necessary ?

提交回复
热议问题