Zend_Cache_Backend_Sqlite vs Zend_Cache_Backend_Fi

2019-06-21 23:56发布

Currently i'm using Zend_Cache_Backend_File for caching my project (especially responses from external web services). I was wandering if I could find some benefit in migrating the structure to Zend_Cache_Backend_Sqlite.

Possible advantages are:

  • File system is well-ordered (only 1 file in cache folder)
  • Removing expired entries should be quicker (my assumption, since zend wouldn't need to scan internal-metadatas for expiring date of each cache)

Possible disadvantages:

  • Finding record to read (with files zend check if file exists based on filename and should be a bit quicker) in term of speed.

I've tried to search a bit in internet but it seems that there are not a lot of discussion about the matter.

What do you think about it?

Thanks in advance.

2条回答
再贱就再见
2楼-- · 2019-06-22 00:30

I'd say, it depends on your application.

Switch shouldn't be hard. Just test both cases, and see which is the best for you. No benchmark is objective except your own.

Measuring just performance, Zend_Cache_Backend_Static is the fastest one.

查看更多
霸刀☆藐视天下
3楼-- · 2019-06-22 00:31

One other disadvantage of Zend_Cache_Backend_File is that if you have a lot of cache files it could take your OS a long time to load a single one because it has to open and scan the entire cache directory each time. So say you have 10,000 cache files, try doing an ls shell command on the cache dir to see how long it takes to read in all the files and print the list. This same lag will translate to your app every time the cache needs to be accessed.

You can use the hashed_directory_level option to mitigate this issue a bit, but it only nests up to two directories deep, which may not be enough if you have a lot of cache files. I ran into this problem on a project, causing performance to actually degrade over time as the cache got bigger and bigger. We couldn't switch to Zend_Cache_Backend_Memcached because we needed tag functionality (not supported by Memcached). Switching to Zend_Cache_Backend_Sqlite is a good option to solve this performance degradation problem.

查看更多
登录 后发表回答