Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
577 views
in Technique[技术] by (71.8m points)

caching - Cache Object in PHP without using serialize

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 unserializing and rebuilding it. Using xdebug I find that I spend half of the entire request time building this object. Even when I store the object explicitly in APC (or memcache), the time to unserialize it and load all of the classes takes almost as long as creating the object in the first place.

I do not know if it is possible to store and later load a "compiled" object in PHP. Is this possible? Are there other solutions?

I am not sure that this is possible, but I thought I should ask the community.

EDIT: The object is a binary tree, and used as a decision tree. The code is basically an API that is required to quickly return an answer from the tree. This all needs to perform at an ever increasing rate so I am trying to maximize the performance wherever possible.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

As far as I'm aware, it's not possible to cache objects in PHP without serializing. In general, however, caching mechanisms (APC, Memcache, etc) are really trying to remove the db connection(s) more than improve performance (and thereby decrease the overall DB strain). This is definitely how memcache, et al are employed with regards to Drupal. In other words, the caching mechanisms should allow you to scale, though they may not particularly improve performance.
Implementing a caching mechanism should allow you to more easily scale outward, even if the performance per machine is no better than before for a single connection. At a certain threshold, DB performance will degrade sharply, and the caching mechanisms should help alleviate that issue.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...