1010#include < LibURL/URL.h>
1111#include < RequestServer/Cache/DiskCache.h>
1212#include < RequestServer/Cache/Utilities.h>
13+ #include < RequestServer/Request.h>
1314
1415namespace RequestServer {
1516
@@ -32,45 +33,45 @@ DiskCache::DiskCache(NonnullRefPtr<Database::Database> database, LexicalPath cac
3233{
3334}
3435
35- Optional<CacheEntryWriter&> DiskCache::create_entry (URL::URL const & url, StringView method, UnixDateTime request_time )
36+ Optional<CacheEntryWriter&> DiskCache::create_entry (Request& request )
3637{
37- if (!is_cacheable (method))
38+ if (!is_cacheable (request. method () ))
3839 return {};
3940
40- auto serialized_url = serialize_url_for_cache_storage (url);
41- auto cache_key = create_cache_key (serialized_url, method);
41+ auto serialized_url = serialize_url_for_cache_storage (request. url () );
42+ auto cache_key = create_cache_key (serialized_url, request. method () );
4243
43- auto cache_entry = CacheEntryWriter::create (*this , m_index, cache_key, move (serialized_url), request_time );
44+ auto cache_entry = CacheEntryWriter::create (*this , m_index, cache_key, move (serialized_url), request. request_start_time () );
4445 if (cache_entry.is_error ()) {
45- dbgln (" \033 [31;1mUnable to create cache entry for\033 [0m {}: {}" , url, cache_entry.error ());
46+ dbgln (" \033 [31;1mUnable to create cache entry for\033 [0m {}: {}" , request. url () , cache_entry.error ());
4647 return {};
4748 }
4849
49- dbgln (" \033 [32;1mCreated disk cache entry for\033 [0m {}" , url);
50+ dbgln (" \033 [32;1mCreated disk cache entry for\033 [0m {}" , request. url () );
5051
5152 auto address = reinterpret_cast <FlatPtr>(cache_entry.value ().ptr ());
5253 m_open_cache_entries.set (address, cache_entry.release_value ());
5354
5455 return static_cast <CacheEntryWriter&>(**m_open_cache_entries.get (address));
5556}
5657
57- Optional<CacheEntryReader&> DiskCache::open_entry (URL::URL const & url, StringView method )
58+ Optional<CacheEntryReader&> DiskCache::open_entry (Request& request )
5859{
59- if (!is_cacheable (method))
60+ if (!is_cacheable (request. method () ))
6061 return {};
6162
62- auto serialized_url = serialize_url_for_cache_storage (url);
63- auto cache_key = create_cache_key (serialized_url, method);
63+ auto serialized_url = serialize_url_for_cache_storage (request. url () );
64+ auto cache_key = create_cache_key (serialized_url, request. method () );
6465
6566 auto index_entry = m_index.find_entry (cache_key);
6667 if (!index_entry.has_value ()) {
67- dbgln (" \033 [35;1mNo disk cache entry for\033 [0m {}" , url);
68+ dbgln (" \033 [35;1mNo disk cache entry for\033 [0m {}" , request. url () );
6869 return {};
6970 }
7071
7172 auto cache_entry = CacheEntryReader::create (*this , m_index, cache_key, index_entry->data_size );
7273 if (cache_entry.is_error ()) {
73- dbgln (" \033 [31;1mUnable to open cache entry for\033 [0m {}: {}" , url, cache_entry.error ());
74+ dbgln (" \033 [31;1mUnable to open cache entry for\033 [0m {}: {}" , request. url () , cache_entry.error ());
7475 m_index.remove_entry (cache_key);
7576 return {};
7677 }
@@ -79,12 +80,12 @@ Optional<CacheEntryReader&> DiskCache::open_entry(URL::URL const& url, StringVie
7980 auto current_age = calculate_age (cache_entry.value ()->headers (), index_entry->request_time , index_entry->response_time );
8081
8182 if (!is_response_fresh (freshness_lifetime, current_age)) {
82- dbgln (" \033 [33;1mCache entry expired for\033 [0m {} (lifetime={}s age={}s)" , url, freshness_lifetime.to_seconds (), current_age.to_seconds ());
83+ dbgln (" \033 [33;1mCache entry expired for\033 [0m {} (lifetime={}s age={}s)" , request. url () , freshness_lifetime.to_seconds (), current_age.to_seconds ());
8384 cache_entry.value ()->remove ();
8485 return {};
8586 }
8687
87- dbgln (" \033 [32;1mOpened disk cache entry for\033 [0m {} (lifetime={}s age={}s) ({} bytes)" , url, freshness_lifetime.to_seconds (), current_age.to_seconds (), index_entry->data_size );
88+ dbgln (" \033 [32;1mOpened disk cache entry for\033 [0m {} (lifetime={}s age={}s) ({} bytes)" , request. url () , freshness_lifetime.to_seconds (), current_age.to_seconds (), index_entry->data_size );
8889
8990 auto address = reinterpret_cast <FlatPtr>(cache_entry.value ().ptr ());
9091 m_open_cache_entries.set (address, cache_entry.release_value ());
0 commit comments