Cache Zend_Db_Table MetaData with Zend_Cache
Khanh is a full stack web developer with over 15 years of experience developing for the web
Search for a command to run...
Khanh is a full stack web developer with over 15 years of experience developing for the web
No comments yet. Be the first to comment.
Elevate your bus reservation experience (or even movie, theater, train, ship, plane tickets) with the React Bus Seat Map Picker – a sophisticated and meticulously crafted script designed exclusively for bus seat bookings. Engineered with strict TypeS...

In previous blog, I migrated all posts from my WordPress to Hashnode at https://blog.donamkhanh.com. Now I create a simple landing page for my main domain and hosted on Github Page. You can access at https://donamkhanh.com. In feature, I'm going to h...

I just finished migrating my blog from Wordpress (self hosted on DigitalOcean) to Hashnode. How did I migrate? I don't have too many articles on Wordpress but I don't like doing it manually so the first thing I did was look to see if there was an aut...

Dự án mình đang làm có yêu cầu sử dụng Azure Active Directory (AAD) để lưu trữ thông tin người dùng & xác thực đăng nhập các kiểu. Ngoài các trường thông tin cơ bản mà AAD hỗ trợ ra thì dự án mình cần lưu thêm 1 số thông tùy chọn khác cho người dùng....

Introduction This is a concise front-end application developed with Angular. You can create a beautiful form with drag and drop visualization. You can get inspiration from it to make a draggable form; at the same time, you can also modify it to suit ...

In this afternoon, my boss asked me to improve performance of project to release to client before Lunar new year holidays. The problem is: we have too many DESCRIBE query on every page load. I Google-ed & found the Lysender's solution, simple & easy to fix this problem:
When you are using Zend_Db_Table (I sometimes only used Zend_Db) you will notice that when you try to retrieve data from the database, the first query called is to DESCRIBE the table. Zend_Db_Table uses the information on DESCRIBE query to do its magic on SELECT.
As I have profiled my queries, I noticed that DESCRIBE query is the longest query (in most cases) which mean a big overhead over you retrieval operation. You have two options:
- Don’t use Zend_Db_Table (go for Zend_Db)
- Cache the MetaData
On this post, I’ll use the caching of MetaData. On your bootstrap file, put this piece of code:
//Caching $frontendOptions = array( 'lifetime' => 25200, 'automatic_serialization' => true ); $backendOptions = array( 'cache_dir' => APPLICATION_PATH . '/tmp' ); $cache = Zend_Cache::factory( 'Core', 'File', $frontendOptions, $backendOptions ); //Cache table metadata Zend_Db_Table_Abstract::setDefaultMetadataCache($cache);
The code simply instructs Zend_Db_Table_Abstract to cache the result of DESCRIBE statement so that next time you retrieve data, the cache is used instead of repeatedly describing tables over and over again.
(But I noticed that INSERT and UPDATE statements don’t have DESCRIBE…)
After several tries with this caching, you will see files on the tmp folder like this: zend_cache—internal-metadatas—5e7576e3cd79114d46850714e998a3b0.
Still there is an overhead on reading the cache file. If you want better caching, use memory based caching like MemCache.
Source: http://lysender.co.cc/2009/03/zend-framework-optimization-tips