Object Cache
Learning Focus
By the end of this lesson you will understand the role of object caching, how it differs from page caching, and when to use Redis or Memcached with OpenLiteSpeed.
What Object Cache Does
Object caching stores the results of expensive database queries or computations in memory so they can be reused across requests. Unlike LiteSpeed page cache (which caches entire HTML responses), object cache works at the application level.
Page Cache vs Object Cache
| Cache Type | What It Stores | Scope | Best For |
|---|---|---|---|
| LiteSpeed Cache | Full HTML pages | Server-level | Anonymous page views |
| Object Cache | Database queries, API results, computed values | Application-level | Dynamic content, logged-in users |
| Browser Cache | Static files (CSS, JS, images) | Client-side | Repeat visits |
When to Use Object Cache
- Logged-in user experiences where page cache does not apply
- Frequent database queries that return the same results
- WordPress sites with plugins that support object cache adapters
- High-traffic sites where database load needs reduction
Common Object Cache Backends
| Backend | Best For | Install |
|---|---|---|
| Redis | Persistent, flexible, feature-rich | sudo apt install redis-server |
| Memcached | Simple, fast key-value storage | sudo apt install memcached |
Quick Redis Setup
# Install Redis
sudo apt install redis-server
# Enable and start
sudo systemctl enable redis-server
sudo systemctl start redis-server
# Verify
redis-cli ping
# Expected: PONG
# Install PHP Redis extension
sudo apt install lsphp84-redis
# Restart OpenLiteSpeed
sudo /usr/local/lsws/bin/lswsctrl restart
info
OpenLiteSpeed itself does not replace Redis or Memcached object caching. It handles page-level caching while the object cache handles application-level data.
Key Takeaways
- Object cache stores database queries and computed values in memory.
- Pair LiteSpeed Cache with object cache for dynamic workloads.
- Redis is the most popular choice for PHP applications like WordPress.
What's Next
- Continue to Cache Rules to learn how to design effective caching policies.