ladybird/Libraries/LibHTTP/Cache
Aliaksandr Kalenik 14dc9e8ca2 LibHTTP: Short-circuit CacheIndex eviction when under its size limit
remove_entries_exceeding_cache_limit() is called after every network
response, but the cache is usually still under budget and nothing needs
to evict. Every one of those calls currently still runs the
window-function eviction SQL over the whole CacheIndex table just to
conclude there is nothing to do.

Short-circuit the call when the cache is already within its configured
size limit. To make that check cheap, maintain m_total_estimated_size
as a running total of the cache's estimated byte size, so the no-op
case becomes a single u64 compare and the DB is only touched when
there is real work.

Bookkeeping:
- Seed the total in CacheIndex::create() via a new
  select_total_estimated_size statement (COALESCE(..., 0) so an empty
  index returns 0 rather than NULL).
- Each Entry caches serialized_request_headers_size and
  serialized_response_headers_size so we don't re-serialize to
  recompute its footprint; Entry::estimated_size() centralizes the
  arithmetic.
- create_entry() adds the new entry's size. Any row it displaces is
  removed via DELETE ... RETURNING so the total stays accurate even
  for entries that were never loaded into m_entries.
- remove_entry() and the bulk DELETE statements were extended with
  the same RETURNING clause for the same reason.
- update_response_headers() shifts the total by the signed delta
  between old and new serialized header size.

Also COALESCEs estimate_cache_size_accessed_since over an empty table
to 0 so callers don't have to special-case NULL.
2026-04-19 01:31:37 +02:00
..
CacheEntry.cpp LibHTTP: Impose a limit on singular disk cache entry sizes 2026-02-13 10:20:52 -05:00
CacheEntry.h RequestServer: Do not flush the disk cache for unsuccessful requests 2026-01-23 14:24:20 +01:00
CacheIndex.cpp LibHTTP: Short-circuit CacheIndex eviction when under its size limit 2026-04-19 01:31:37 +02:00
CacheIndex.h LibHTTP: Short-circuit CacheIndex eviction when under its size limit 2026-04-19 01:31:37 +02:00
CacheMode.h LibHTTP+LibWeb+RequestServer: Handle the Fetch API's cache mode 2026-01-22 07:05:06 -05:00
CacheRequest.h LibHTTP+RequestServer: Implement the stale-while-revalidate directive 2025-12-13 13:07:02 -06:00
DiskCache.cpp LibHTTP: Use a memory-backed database for the disk cache in test modes 2026-02-15 15:25:30 -05:00
DiskCache.h LibHTTP: Use IdentityHashTraits for HashMaps keyed by the cache key 2026-02-24 15:10:59 +01:00
DiskCacheSettings.cpp LibHTTP+LibWebView+RequestServer: Allow users to set disk cache limits 2026-02-13 10:20:52 -05:00
DiskCacheSettings.h LibHTTP+LibWebView+RequestServer: Allow users to set disk cache limits 2026-02-13 10:20:52 -05:00
MemoryCache.cpp LibHTTP: Honor the no-cache Cache-Control request directive 2026-01-28 11:31:04 -05:00
MemoryCache.h LibHTTP: Use IdentityHashTraits for HashMaps keyed by the cache key 2026-02-24 15:10:59 +01:00
Utilities.cpp LibHTTP: Correctly normalize header whitespace in cache utilities 2026-02-26 22:27:46 +01:00
Utilities.h LibHTTP: Use a memory-backed database for the disk cache in test modes 2026-02-15 15:25:30 -05:00
Version.h LibHTTP+LibWeb: Support the HTTP Vary response header 2026-01-22 08:54:49 -05:00