开发者

PHP: Efficient way to store simple cache array in database?

Basically for a plugin for a dynamic site (site can be fairly large) I am caching results of some sort of search (because results are from an external search), the results can 开发者_如何学Pythonbe 400-1500 characters in length.

As the results come in an array, I use json_encode (faster than serialize) to store in the database, but ~1.5KB per entry (since there may be 10,000)=15MB seems a little large for me.

My questions are:

* Is this an acceptable (your opinion) size per entry?

* Will running GZip or similar and storing in a binary field in MySQL be more efficient or take too much CPU time in the end? Anything normally used similar?

I prefer to not use memcached or alike as it's needed to be portable (but would that be better as well?) this is mostly a theory question for me, I just require input before I implement anything solid.


There will always be a CPU Cost for any kind of compression, it depends if you have the resources to handle it without any noticeable slowdown. Space is cheap and abundant, so 15megs is ok.

But if you really want to compress your field, then check out Mysql's COMPRESS() and UNCOMPRESS() functions.

This could be dropped into your code and it would work without changing any PHP/Logic.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜