mirror of
https://github.com/RGBCube/serenity
synced 2025-07-25 04:27:43 +00:00
LibWeb: Add a naive Resource cache
This patch introduces a caching mechanism in ResourceLoader. It's keyed on a LoadRequest object which is what you provide to load_resource() when you want to load a resource. We currently never prune the cache, so resources will stay in there forever. This is obviously not gonna stay that way, but we're just getting started here. :^) This should drastically reduce the number of requests when loading some sites (like Twitter) that reuse the same images over and over.
This commit is contained in:
parent
f249f07699
commit
7af337764e
7 changed files with 94 additions and 15 deletions
|
@ -33,6 +33,7 @@
|
|||
#include <AK/RefCounted.h>
|
||||
#include <AK/URL.h>
|
||||
#include <LibWeb/Forward.h>
|
||||
#include <LibWeb/Loader/LoadRequest.h>
|
||||
|
||||
namespace Web {
|
||||
|
||||
|
@ -43,7 +44,7 @@ class Resource : public RefCounted<Resource> {
|
|||
AK_MAKE_NONMOVABLE(Resource);
|
||||
|
||||
public:
|
||||
static NonnullRefPtr<Resource> create(Badge<ResourceLoader>, const URL&);
|
||||
static NonnullRefPtr<Resource> create(Badge<ResourceLoader>, const LoadRequest&);
|
||||
~Resource();
|
||||
|
||||
bool is_loaded() const { return m_loaded; }
|
||||
|
@ -53,7 +54,7 @@ public:
|
|||
|
||||
bool has_encoded_data() const { return !m_encoded_data.is_null(); }
|
||||
|
||||
const URL& url() const { return m_url; }
|
||||
const URL& url() const { return m_request.url(); }
|
||||
const ByteBuffer& encoded_data() const { return m_encoded_data; }
|
||||
|
||||
void register_client(Badge<ResourceClient>, ResourceClient&);
|
||||
|
@ -75,9 +76,9 @@ public:
|
|||
void did_fail(Badge<ResourceLoader>, const String& error);
|
||||
|
||||
private:
|
||||
explicit Resource(const URL&);
|
||||
explicit Resource(const LoadRequest&);
|
||||
|
||||
URL m_url;
|
||||
LoadRequest m_request;
|
||||
ByteBuffer m_encoded_data;
|
||||
bool m_loaded { false };
|
||||
bool m_failed { false };
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue