Skip to main content

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 TypeWhat It StoresScopeBest For
LiteSpeed CacheFull HTML pagesServer-levelAnonymous page views
Object CacheDatabase queries, API results, computed valuesApplication-levelDynamic content, logged-in users
Browser CacheStatic files (CSS, JS, images)Client-sideRepeat 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

BackendBest ForInstall
RedisPersistent, flexible, feature-richsudo apt install redis-server
MemcachedSimple, fast key-value storagesudo 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.