You are viewing revision #2 of this wiki article.
This is the latest version of this article.
You may want to see the changes made in this revision.
Hey everyone,
I’m working on a Yii 1.x–based ERP/POS system and recently implemented Redis caching for performance optimization. Thought I’d share my setup and a few lessons learned in case it helps someone still maintaining Yii 1.x apps.
My Setup ¶
'components'=>array(
'cache'=>array(
'class'=>'CRedisCache',
'hostname'=>'127.0.0.1',
'port'=>6379,
'database'=>1,
'keyPrefix'=>'database',
),
),
Why Redis Instead of FileCache? ¶
- Much faster read/write (RAM-based)
- Great for high-traffic POS/ERP environments
- Reduces DB load significantly
- Works well for session + query caching
✅ Where I’m Using Cache ¶
- Product listing queries (heavy joins)
- Dashboard stats (sales, stock, reports)
- API responses for branch sync
- Session handling (planning to shift fully to Redis)
Things to Watch Out For ¶
Key Prefix is Important If you’re running multiple apps on same Redis instance, always use
keyPrefixto avoid conflicts.Cache Invalidation Yii 1.x doesn’t auto-handle this well. You need to manually clear cache when:
- product updates
- stock changes
- price updates
Persistence Redis is in-memory. Make sure:
- RDB or AOF is enabled (depending on your setup)
- Otherwise you risk data loss on restart
Production Deployment Don’t keep Redis on default config:
- bind to private IP
- use password (requirepass)
- firewall the port
Example Usage ¶
$key = 'product_list';
$data = Yii::app()->cache->get($key);
if ($data === false) {
$data = Product::model()->findAll();
Yii::app()->cache->set($key, $data, 300); // cache for 5 minutes
}
Question for Community ¶
For those still on Yii 1.x:
- Are you using Redis for sessions as well?
- Any best practices for automatic cache invalidation?
Would love to hear how others are optimizing legacy Yii apps in production.
Thanks!
User Contributed Notes
Leave a comment
If you have any questions, please ask in the forum instead.
Join the conversation to share a note.