Interview question
What caching strategies are available in PHP applications? PHP applications में कौन-सी caching strategies उपलब्ध हैं?
Answer
| Caching type | What it stores | Tool examples |
|---|---|---|
| Opcode caching | Compiled PHP bytecode | OPcache |
| Data/object caching | Query results, computed values | Redis, Memcached |
| Full-page caching | Entire rendered HTML response | Varnish, CDN edge cache |
| Fragment caching | Parts of a page (e.g. sidebar) | Blade @cache, application logic |
// Laravel example - cache expensive query for 1 hour
$products = Cache::remember('featured_products', 3600, function () {
return Product::where('featured', true)->get();
});The right strategy depends on how often data changes - full-page caching suits mostly-static content, while data caching suits frequently-read but rarely-written data.
| Caching type | क्या store करता है | Tools |
|---|---|---|
| Opcode caching | Compiled bytecode | OPcache |
| Data caching | Query results | Redis, Memcached |
| Full-page caching | पूरा HTML response | Varnish, CDN |
$products = Cache::remember('featured_products', 3600, function () {
return Product::where('featured', true)->get();
});Was this answer clear?