michael-o commented on code in PR #429: URL: https://github.com/apache/httpcomponents-client/pull/429#discussion_r1154062956
########## httpclient5-cache/src/main/java/org/apache/hc/client5/http/impl/cache/HttpByteArrayCacheEntrySerializer.java: ########## @@ -42,36 +44,68 @@ import org.apache.hc.client5.http.cache.HttpCacheStorageEntry; import org.apache.hc.client5.http.cache.Resource; import org.apache.hc.client5.http.cache.ResourceIOException; -import org.apache.hc.core5.annotation.Experimental; -import org.apache.hc.core5.http.Header; +import org.apache.hc.core5.annotation.Contract; +import org.apache.hc.core5.annotation.ThreadingBehavior; import org.apache.hc.core5.http.ClassicHttpResponse; +import org.apache.hc.core5.http.Header; import org.apache.hc.core5.http.HttpException; import org.apache.hc.core5.http.HttpRequest; import org.apache.hc.core5.http.HttpResponse; import org.apache.hc.core5.http.HttpVersion; import org.apache.hc.core5.http.ProtocolVersion; +import org.apache.hc.core5.http.config.Http1Config; import org.apache.hc.core5.http.impl.io.AbstractMessageParser; import org.apache.hc.core5.http.impl.io.AbstractMessageWriter; import org.apache.hc.core5.http.impl.io.DefaultHttpResponseParser; import org.apache.hc.core5.http.impl.io.SessionInputBufferImpl; import org.apache.hc.core5.http.impl.io.SessionOutputBufferImpl; import org.apache.hc.core5.http.io.SessionInputBuffer; import org.apache.hc.core5.http.io.SessionOutputBuffer; +import org.apache.hc.core5.http.message.BasicHeader; import org.apache.hc.core5.http.message.BasicHttpRequest; import org.apache.hc.core5.http.message.BasicLineFormatter; +import org.apache.hc.core5.http.message.HeaderGroup; +import org.apache.hc.core5.http.message.LazyLineParser; import org.apache.hc.core5.http.message.StatusLine; import org.apache.hc.core5.util.CharArrayBuffer; import org.apache.hc.core5.util.TimeValue; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; /** - * Cache serializer and deserializer that uses an HTTP-like format. + * Serializes and deserializes byte arrays into HTTP cache entries using a default buffer size of 8192 bytes. + * The cache entries contain an HTTP response generated from the byte array data, which can be used to generate + * HTTP responses for cache hits. + * <p> + * This implementation uses the Apache HttpComponents library to perform the serialization and deserialization. + * <p> + * To serialize a byte array into an HTTP cache entry, use the {@link #serialize(HttpCacheStorageEntry)} method. To deserialize an HTTP cache + * entry into a byte array, use the {@link #deserialize(byte[])} method. + * <p> + * This class implements the {@link HttpCacheEntrySerializer} interface, which defines the contract for HTTP cache + * entry serialization and deserialization. It also includes a default buffer size of 8192 bytes, which can be + * overridden by specifying a different buffer size in the constructor. + * <p> + * Note that this implementation only supports HTTP responses and does not support HTTP requests or any other types of + * HTTP messages. * - * Existing libraries for reading and writing HTTP are used, and metadata is encoded into HTTP - * pseudo-headers for storage. + * @since 5.3 */ -@Experimental +@Contract(threading = ThreadingBehavior.STATELESS) public class HttpByteArrayCacheEntrySerializer implements HttpCacheEntrySerializer<byte[]> { - public static final HttpByteArrayCacheEntrySerializer INSTANCE = new HttpByteArrayCacheEntrySerializer(); + + private static final Logger LOG = LoggerFactory.getLogger(HttpByteArrayCacheEntrySerializer.class); + + /** + * The default buffer size used for I/O operations, set to 8192 bytes. + */ + private static final int DEFAULT_BUFFER_SIZE = 8192; + + /** + * Singleton instance of this class. + */ + public static final HttpByteArrayCacheEntrySerializer INSTANCE = new HttpByteArrayCacheEntrySerializer(DEFAULT_BUFFER_SIZE); + private static final String SC_CACHE_ENTRY_PREFIX = "hc-"; Review Comment: This recommendation is obsolete for many years. -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: dev-unsubscr...@hc.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org --------------------------------------------------------------------- To unsubscribe, e-mail: dev-unsubscr...@hc.apache.org For additional commands, e-mail: dev-h...@hc.apache.org