-
Notifications
You must be signed in to change notification settings - Fork 983
HTTPCLIENT-2277: optimization of internal cache operations #464
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,60 @@ | ||
| /* | ||
| * ==================================================================== | ||
| * Licensed to the Apache Software Foundation (ASF) under one | ||
| * or more contributor license agreements. See the NOTICE file | ||
| * distributed with this work for additional information | ||
| * regarding copyright ownership. The ASF licenses this file | ||
| * to you under the Apache License, Version 2.0 (the | ||
| * "License"); you may not use this file except in compliance | ||
| * with the License. You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, | ||
| * software distributed under the License is distributed on an | ||
| * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
| * KIND, either express or implied. See the License for the | ||
| * specific language governing permissions and limitations | ||
| * under the License. | ||
| * ==================================================================== | ||
| * | ||
| * This software consists of voluntary contributions made by many | ||
| * individuals on behalf of the Apache Software Foundation. For more | ||
| * information on the Apache Software Foundation, please see | ||
| * <http://www.apache.org/>. | ||
| * | ||
| */ | ||
| package org.apache.hc.client5.http.impl.cache; | ||
|
|
||
| import org.apache.hc.client5.http.cache.HttpCacheEntry; | ||
|
|
||
| class CacheHit { | ||
|
|
||
| final String rootKey; | ||
| final String variantKey; | ||
| final HttpCacheEntry entry; | ||
|
|
||
| public CacheHit(final String rootKey, final String variantKey, final HttpCacheEntry entry) { | ||
| this.rootKey = rootKey; | ||
| this.variantKey = variantKey; | ||
| this.entry = entry; | ||
| } | ||
|
|
||
| public CacheHit(final String rootKey, final HttpCacheEntry entry) { | ||
| this(rootKey, null, entry); | ||
| } | ||
|
|
||
| public String getEntryKey() { | ||
| return variantKey != null ? variantKey : rootKey; | ||
| } | ||
|
|
||
| @Override | ||
| public String toString() { | ||
| return "CacheHit{" + | ||
| "rootKey='" + rootKey + '\'' + | ||
| ", variantKey='" + variantKey + '\'' + | ||
| ", entry=" + entry + | ||
| '}'; | ||
| } | ||
|
|
||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -26,30 +26,26 @@ | |
| */ | ||
| package org.apache.hc.client5.http.impl.cache; | ||
|
|
||
| import org.apache.hc.client5.http.cache.HttpCacheEntry; | ||
|
|
||
| /** Records a set of information describing a cached variant. */ | ||
| class Variant { | ||
|
|
||
| private final String cacheKey; | ||
| private final HttpCacheEntry entry; | ||
|
|
||
| public Variant(final String cacheKey, final HttpCacheEntry entry) { | ||
| this.cacheKey = cacheKey; | ||
| this.entry = entry; | ||
| } | ||
| /** | ||
| * Represents a full match or a partial match (variant options) | ||
| * result of a cache lookup operation. | ||
| */ | ||
| class CacheMatch { | ||
|
|
||
| public String getCacheKey() { | ||
| return cacheKey; | ||
| } | ||
| final CacheHit hit; | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Shouldn't this class be fully immutable?
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @arturobernalg It is. All its instance variables are final and immutable. There are no access methods but that does not make the class mutable. |
||
| final CacheHit root; | ||
|
|
||
| public HttpCacheEntry getEntry() { | ||
| return entry; | ||
| CacheMatch(final CacheHit hit, final CacheHit root) { | ||
| this.hit = hit; | ||
| this.root = root; | ||
| } | ||
|
|
||
| @Override | ||
| public String toString() { | ||
| return cacheKey; | ||
| return "CacheLookupResult{" + | ||
| "hit=" + hit + | ||
| ", root=" + root + | ||
| '}'; | ||
| } | ||
|
|
||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Shouldn't this class be fully immutable? Also, shouldn't
rootKeyandentrybe null-safe?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@arturobernalg The class is immutable. It is also internal so I forwent getters and null checks for its instance variables.