Skip to content

Commit 68e4bd3

Browse files
authored
Cleanup HttpCacheKey (#12739)
* Remove unused HttpCacheKey::hash2 * Use std::string_view for HttpCacheKey::hostname
1 parent 90e2d1d commit 68e4bd3

File tree

3 files changed

+8
-18
lines changed

3 files changed

+8
-18
lines changed

include/iocore/cache/CacheDefs.h

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -129,10 +129,8 @@ enum CacheFragType {
129129
using CacheKey = CryptoHash;
130130

131131
struct HttpCacheKey {
132-
int hostlen;
133-
const char *hostname;
134-
CacheKey hash;
135-
CacheKey hash2;
132+
std::string_view hostname;
133+
CacheKey hash;
136134
};
137135

138136
#define CACHE_ALLOW_MULTIPLE_WRITES 1

src/iocore/cache/CacheProcessor.cc

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -406,24 +406,21 @@ CacheProcessor::scan(Continuation *cont, std::string_view hostname, int KB_per_s
406406
Action *
407407
CacheProcessor::lookup(Continuation *cont, const HttpCacheKey *key, CacheFragType frag_type)
408408
{
409-
return lookup(cont, &key->hash, frag_type,
410-
std::string_view{key->hostname, static_cast<std::string_view::size_type>(key->hostlen)});
409+
return lookup(cont, &key->hash, frag_type, key->hostname);
411410
}
412411

413412
Action *
414413
CacheProcessor::open_read(Continuation *cont, const HttpCacheKey *key, CacheHTTPHdr *request, const HttpConfigAccessor *params,
415414
CacheFragType type)
416415
{
417-
return caches[type]->open_read(cont, &key->hash, request, params, type,
418-
std::string_view{key->hostname, static_cast<std::string_view::size_type>(key->hostlen)});
416+
return caches[type]->open_read(cont, &key->hash, request, params, type, key->hostname);
419417
}
420418

421419
Action *
422420
CacheProcessor::open_write(Continuation *cont, const HttpCacheKey *key, CacheHTTPInfo *old_info, time_t pin_in_cache,
423421
CacheFragType type)
424422
{
425-
return caches[type]->open_write(cont, &key->hash, old_info, pin_in_cache, type,
426-
std::string_view{key->hostname, static_cast<std::string_view::size_type>(key->hostlen)});
423+
return caches[type]->open_write(cont, &key->hash, old_info, pin_in_cache, type, key->hostname);
427424
}
428425

429426
//----------------------------------------------------------------------------
@@ -432,8 +429,7 @@ CacheProcessor::open_write(Continuation *cont, const HttpCacheKey *key, CacheHTT
432429
Action *
433430
CacheProcessor::remove(Continuation *cont, const HttpCacheKey *key, CacheFragType frag_type)
434431
{
435-
return caches[frag_type]->remove(cont, &key->hash, frag_type,
436-
std::string_view{key->hostname, static_cast<std::string_view::size_type>(key->hostlen)});
432+
return caches[frag_type]->remove(cont, &key->hash, frag_type, key->hostname);
437433
}
438434

439435
/** Set the state of a disk programmatically.

src/iocore/cache/P_CacheInternal.h

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -497,9 +497,7 @@ Cache::generate_key(CryptoHash *hash, CacheURL *url)
497497
inline void
498498
Cache::generate_key(HttpCacheKey *key, CacheURL *url, bool ignore_query, cache_generation_t generation)
499499
{
500-
auto host{url->host_get()};
501-
key->hostname = host.data();
502-
key->hostlen = static_cast<int>(host.length());
500+
key->hostname = url->host_get();
503501
url->hash_get(&key->hash, ignore_query, generation);
504502
}
505503

@@ -512,9 +510,7 @@ Cache::generate_key92(CryptoHash *hash, CacheURL *url)
512510
inline void
513511
Cache::generate_key92(HttpCacheKey *key, CacheURL *url, bool ignore_query, cache_generation_t generation)
514512
{
515-
auto host{url->host_get()};
516-
key->hostname = host.data();
517-
key->hostlen = static_cast<int>(host.length());
513+
key->hostname = url->host_get();
518514
url->hash_get92(&key->hash, ignore_query, generation);
519515
}
520516

0 commit comments

Comments
 (0)