-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
This guarantess that hashes are only calculated once, and not twice (lookup and store). And it gives more control over how and when the hash is calculated; since HttpCache has calculation hurts a lot, it is now possible to use an optimized hash formula.
- Loading branch information
1 parent
41b2e18
commit ae56628
Showing
16 changed files
with
226 additions
and
230 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,27 +3,6 @@ | |
// author: Max Kellermann <[email protected]> | ||
|
||
#include "Item.hxx" | ||
#include "util/djb_hash.hxx" | ||
#include "util/StringAPI.hxx" | ||
|
||
#include <cassert> | ||
|
||
size_t | ||
CacheItem::Hash::operator()(const char *_key) const noexcept | ||
{ | ||
assert(_key != nullptr); | ||
|
||
return djb_hash_string(_key); | ||
} | ||
|
||
bool | ||
CacheItem::Equal::operator()(const char *a, const char *b) const noexcept | ||
{ | ||
assert(a != nullptr); | ||
assert(b != nullptr); | ||
|
||
return StringIsEqual(a, b); | ||
} | ||
|
||
static constexpr std::chrono::steady_clock::time_point | ||
ToSteady(std::chrono::steady_clock::time_point steady_now, | ||
|
@@ -35,15 +14,15 @@ ToSteady(std::chrono::steady_clock::time_point steady_now, | |
: std::chrono::steady_clock::time_point(); | ||
} | ||
|
||
CacheItem::CacheItem(const char *_key, std::size_t _size, | ||
CacheItem::CacheItem(StringWithHash _key, std::size_t _size, | ||
std::chrono::steady_clock::time_point now, | ||
std::chrono::system_clock::time_point system_now, | ||
std::chrono::system_clock::time_point _expires) noexcept | ||
:CacheItem(_key, _size, ToSteady(now, system_now, _expires)) | ||
{ | ||
} | ||
|
||
CacheItem::CacheItem(const char *_key, std::size_t _size, | ||
CacheItem::CacheItem(StringWithHash _key, std::size_t _size, | ||
std::chrono::steady_clock::time_point now, | ||
std::chrono::seconds max_age) noexcept | ||
:CacheItem(_key, _size, now + max_age) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.