Files
ladybird/Libraries/LibHTTP/Cache/MemoryCache.h
Timothy Flynn 2ac219405f LibHTTP+LibWeb: Purge non-fresh entries from the memory cache
Once a cache entry is not fresh, we now remove it from the memory cache.
We will avoid handling revalidation from within WebContent. Instead, we
will just forward the request to RequestServer, where the disk cache
will handle revalidation for itself if needed.
2026-01-19 08:02:14 -05:00

45 lines
1.2 KiB
C++

/*
* Copyright (c) 2025, Tim Flynn <trflynn89@ladybird.org>
*
* SPDX-License-Identifier: BSD-2-Clause
*/
#pragma once
#include <AK/ByteString.h>
#include <AK/HashMap.h>
#include <AK/NonnullRefPtr.h>
#include <AK/RefCounted.h>
#include <AK/Time.h>
#include <LibHTTP/Forward.h>
#include <LibURL/URL.h>
namespace HTTP {
class MemoryCache : public RefCounted<MemoryCache> {
public:
struct Entry {
u32 status_code { 0 };
ByteString reason_phrase;
NonnullRefPtr<HeaderList> response_headers;
ByteBuffer response_body;
UnixDateTime request_time;
UnixDateTime response_time;
};
static NonnullRefPtr<MemoryCache> create();
Optional<Entry const&> open_entry(URL::URL const&, StringView method, HeaderList const& request_headers);
void create_entry(URL::URL const&, StringView method, HeaderList const& request_headers, UnixDateTime request_time, u32 status_code, ByteString reason_phrase, HeaderList const& response_headers);
void finalize_entry(URL::URL const&, StringView method, ByteBuffer response_body);
private:
HashMap<u64, Entry> m_pending_entries;
HashMap<u64, Entry> m_complete_entries;
};
}