.. index:: pair: class; EE::UI::WebResourceCache .. _doxid-class_e_e_1_1_u_i_1_1_web_resource_cache: class EE::UI::WebResourceCache ============================== .. toctree:: :hidden: Overview ~~~~~~~~ Shared HTTP-backed document resource cache. :ref:`More...` .. ref-code-block:: cpp :class: doxyrest-overview-code-block #include class WebResourceCache: public std::enable_shared_from_this< WebResourceCache > { public: // typedefs typedef std::function`&)> :ref:`Callback`; typedef std::function`)> :ref:`FetchCompletion`; typedef std::function`&, :ref:`FetchCompletion`)> :ref:`Fetcher`; // construction :ref:`~WebResourceCache`(); // methods static :ref:`WebResourceCachePtr` :ref:`New`(); :ref:`CachePartitionId` :ref:`createPartition`(); :ref:`DocumentSessionId` :ref:`createSession`(:ref:`CachePartitionId` partition = 0); void :ref:`destroySession`(:ref:`DocumentSessionId` session); :ref:`Uint64` :ref:`beginNavigation`(:ref:`DocumentSessionId` session, const :ref:`Network::URI`& uri); :ref:`Uint64` :ref:`getSessionGeneration`(:ref:`DocumentSessionId` session) const; :ref:`CachePartitionId` :ref:`getSessionPartition`(:ref:`DocumentSessionId` session) const; void :ref:`requestData`(:ref:`DocumentSessionId` session, :ref:`Uint64` generation, :ref:`WebResourceRequest` request, :ref:`Callback` callback); :ref:`Graphics::TexturePtr` :ref:`requestTexture`(:ref:`DocumentSessionId` session, :ref:`Uint64` generation, :ref:`WebResourceRequest` request, :ref:`Callback` callback = {}); void :ref:`setTTL`(:ref:`System::Time` ttl); :ref:`System::Time` :ref:`getTTL`() const; void :ref:`setRetryDelay`(:ref:`System::Time` delay); :ref:`System::Time` :ref:`getRetryDelay`() const; void :ref:`setByteBudget`(std::size_t bytes); std::size_t :ref:`getByteBudget`() const; std::size_t :ref:`getRetainedBytes`() const; std::size_t :ref:`getEntryCount`() const; std::size_t :ref:`getInFlightCount`() const; void :ref:`prune`(); void :ref:`clear`(); void :ref:`setFetcher`(:ref:`Fetcher` fetcher); }; .. _details-class_e_e_1_1_u_i_1_1_web_resource_cache: Detailed Documentation ~~~~~~~~~~~~~~~~~~~~~~ Shared HTTP-backed document resource cache. The cache separates three concepts: * A partition defines which HTTP/cookie context may share entries. * A session represents one active document using entries from that partition. * A navigation generation prevents an obsolete document from receiving asynchronous results. Entries are strongly retained by the cache after their final document lease is released. Their TTL starts at that release point, allowing Back/Forward navigation to reuse them. Expired entries are removed by :ref:`prune() `; :ref:`UIWebView ` invokes it periodically. A byte budget additionally evicts the least-recently-used unleased entries. Active leases and in-flight loads are not evicted. Requests for the same key are coalesced into one HTTP operation. Each current subscriber receives the result, while callbacks belonging to obsolete navigation generations are discarded. Public operations are internally synchronized. Subscriber callbacks run without the cache mutex held. Typedefs -------- .. index:: pair: typedef; Callback .. _doxid-class_e_e_1_1_u_i_1_1_web_resource_cache_1a778590b8488fee06ffaa1d524026ed87: .. ref-code-block:: cpp :class: doxyrest-title-code-block typedef std::function`&)> Callback Receives the completed result of a data or texture request. .. index:: pair: typedef; FetchCompletion .. _doxid-class_e_e_1_1_u_i_1_1_web_resource_cache_1ab3948e82b23c28c69e868b9aeba1cb59: .. ref-code-block:: cpp :class: doxyrest-title-code-block typedef std::function`)> FetchCompletion Completion supplied to a custom Fetcher. .. index:: pair: typedef; Fetcher .. _doxid-class_e_e_1_1_u_i_1_1_web_resource_cache_1ac76b0d67ca58ebf28d42c23940ee0930: .. ref-code-block:: cpp :class: doxyrest-title-code-block typedef std::function`&, :ref:`FetchCompletion`)> Fetcher Custom fetch implementation, primarily intended for deterministic tests. The fetcher must eventually invoke FetchCompletion exactly once. Production uses Http::requestAsync when no custom fetcher is installed. Construction ------------ .. _doxid-class_e_e_1_1_u_i_1_1_web_resource_cache_1a7a4dbcfedcf1d99503e0cb6e18704509: .. ref-code-block:: cpp :class: doxyrest-title-code-block ~WebResourceCache() Cancels cache delivery and releases all retained entries and sessions. Methods ------- .. index:: pair: function; New .. _doxid-class_e_e_1_1_u_i_1_1_web_resource_cache_1ad7ea073bc465526f7036a2d0fc65d8b1: .. ref-code-block:: cpp :class: doxyrest-title-code-block static :ref:`WebResourceCachePtr` New() .. rubric:: Returns: A newly allocated shared web-resource cache. .. index:: pair: function; createPartition .. _doxid-class_e_e_1_1_u_i_1_1_web_resource_cache_1a6a7c3b760900ba84084a2c26cbd4dbfa: .. ref-code-block:: cpp :class: doxyrest-title-code-block :ref:`CachePartitionId` createPartition() Allocates a new process-wide partition identifier. .. rubric:: Returns: An opaque, non-zero partition ID. .. index:: pair: function; createSession .. _doxid-class_e_e_1_1_u_i_1_1_web_resource_cache_1a0be8a4324d02a551712f8419241e8787: .. ref-code-block:: cpp :class: doxyrest-title-code-block :ref:`DocumentSessionId` createSession(:ref:`CachePartitionId` partition = 0) Creates a document session. .. rubric:: Parameters: .. list-table:: :widths: 20 80 * - partition - Partition to join. Zero creates a new private partition. .. rubric:: Returns: An opaque, non-zero document session ID. .. index:: pair: function; destroySession .. _doxid-class_e_e_1_1_u_i_1_1_web_resource_cache_1a58ed2354d6062f88946180ad19cd4dc4: .. ref-code-block:: cpp :class: doxyrest-title-code-block void destroySession(:ref:`DocumentSessionId` session) Destroys a session and releases all entries leased by it. Releasing the final lease starts each entry's TTL; it does not normally erase entries immediately. Pending callbacks for the destroyed session will not be delivered. .. index:: pair: function; beginNavigation .. _doxid-class_e_e_1_1_u_i_1_1_web_resource_cache_1aa080f462ec5d612f2ae7b9af49c1e570: .. ref-code-block:: cpp :class: doxyrest-title-code-block :ref:`Uint64` beginNavigation(:ref:`DocumentSessionId` session, const :ref:`Network::URI`& uri) Begins a new document navigation in an existing session. Previous document leases are released and the generation is incremented. Pending subscribers from older generations become stale, but shared in-flight requests continue for other current subscribers. .. rubric:: Parameters: .. list-table:: :widths: 20 80 * - session - Session performing the navigation. * - uri - Destination document URI, used to record its origin. .. rubric:: Returns: The new generation, or zero when the session does not exist. .. index:: pair: function; getSessionGeneration .. _doxid-class_e_e_1_1_u_i_1_1_web_resource_cache_1ab71ae3f1c1571eefb4db053ac96ea964: .. ref-code-block:: cpp :class: doxyrest-title-code-block :ref:`Uint64` getSessionGeneration(:ref:`DocumentSessionId` session) const .. rubric:: Returns: The current generation for a session, or zero when it does not exist. .. index:: pair: function; getSessionPartition .. _doxid-class_e_e_1_1_u_i_1_1_web_resource_cache_1aedf5ed1850236b8072e208622b2b9a91: .. ref-code-block:: cpp :class: doxyrest-title-code-block :ref:`CachePartitionId` getSessionPartition(:ref:`DocumentSessionId` session) const .. rubric:: Returns: The partition used by a session, or zero when it does not exist. .. index:: pair: function; requestData .. _doxid-class_e_e_1_1_u_i_1_1_web_resource_cache_1a32a5f5b09c119ee5e0f6a422cf31f6b5: .. ref-code-block:: cpp :class: doxyrest-title-code-block void requestData(:ref:`DocumentSessionId` session, :ref:`Uint64` generation, :ref:`WebResourceRequest` request, :ref:`Callback` callback) Requests a document, stylesheet, font, or other non-texture response body. A ready cache hit may invoke callback synchronously. A miss starts or joins an asynchronous fetch. The callback is omitted when the session/generation is stale. .. rubric:: Parameters: .. list-table:: :widths: 20 80 * - session - Requesting document session. * - generation - Generation returned by :ref:`beginNavigation() `. * - request - Resource and transport description. * - callback - Optional completion callback. .. index:: pair: function; requestTexture .. _doxid-class_e_e_1_1_u_i_1_1_web_resource_cache_1ad01601ccb708a8ba6ae616f3f3c45056: .. ref-code-block:: cpp :class: doxyrest-title-code-block :ref:`Graphics::TexturePtr` requestTexture(:ref:`DocumentSessionId` session, :ref:`Uint64` generation, :ref:`WebResourceRequest` request, :ref:`Callback` callback = {}) Requests an image as a shared texture. On a miss, this creates and returns a transparent placeholder immediately. The same TexturePtr is populated after download and decode. A ready hit returns the existing texture without a new HTTP request. This function must be called where texture creation is valid, and the request must provide an appropriate completionDispatcher for asynchronous GPU upload. .. rubric:: Returns: The cached/new texture, or null for an invalid or stale session. .. index:: pair: function; setTTL .. _doxid-class_e_e_1_1_u_i_1_1_web_resource_cache_1a696827195164b65d14b1ed2fdf5530dd: .. ref-code-block:: cpp :class: doxyrest-title-code-block void setTTL(:ref:`System::Time` ttl) Sets the retention duration used when an entry's final document lease is released. .. index:: pair: function; getTTL .. _doxid-class_e_e_1_1_u_i_1_1_web_resource_cache_1a4ccb66a0653b5c6207ee6d79dc254b5b: .. ref-code-block:: cpp :class: doxyrest-title-code-block :ref:`System::Time` getTTL() const .. rubric:: Returns: The current post-lease retention duration. .. index:: pair: function; setRetryDelay .. _doxid-class_e_e_1_1_u_i_1_1_web_resource_cache_1a8068c1711f79ed6b28b7cc59d88df425: .. ref-code-block:: cpp :class: doxyrest-title-code-block void setRetryDelay(:ref:`System::Time` delay) Sets how long a failed entry suppresses another fetch attempt. .. index:: pair: function; getRetryDelay .. _doxid-class_e_e_1_1_u_i_1_1_web_resource_cache_1aedce5ba9a2186f6e18398e16e6f03063: .. ref-code-block:: cpp :class: doxyrest-title-code-block :ref:`System::Time` getRetryDelay() const .. rubric:: Returns: The current failed-request retry delay. .. index:: pair: function; setByteBudget .. _doxid-class_e_e_1_1_u_i_1_1_web_resource_cache_1a68e2a5162532aa1cf58bb51866b6352e: .. ref-code-block:: cpp :class: doxyrest-title-code-block void setByteBudget(std::size_t bytes) Sets the maximum retained response/texture byte estimate. Applying a smaller budget immediately evicts least-recently-used unleased entries where possible. Active entries may temporarily make retained bytes exceed the budget. .. index:: pair: function; getByteBudget .. _doxid-class_e_e_1_1_u_i_1_1_web_resource_cache_1ac7199036294bb651db480796de192628: .. ref-code-block:: cpp :class: doxyrest-title-code-block std::size_t getByteBudget() const .. rubric:: Returns: The configured retained-byte budget. .. index:: pair: function; getRetainedBytes .. _doxid-class_e_e_1_1_u_i_1_1_web_resource_cache_1ad353a0752a342b0f9ddb98591cbe978a: .. ref-code-block:: cpp :class: doxyrest-title-code-block std::size_t getRetainedBytes() const .. rubric:: Returns: Estimated bytes retained by ready data bodies and decoded image textures. .. index:: pair: function; getEntryCount .. _doxid-class_e_e_1_1_u_i_1_1_web_resource_cache_1ae016a5cf90d9167050ebd4e915f9d5ec: .. ref-code-block:: cpp :class: doxyrest-title-code-block std::size_t getEntryCount() const .. rubric:: Returns: Number of cache entries in all states and partitions. .. index:: pair: function; getInFlightCount .. _doxid-class_e_e_1_1_u_i_1_1_web_resource_cache_1a914e1e1b92ca28ade1a893a670e8ba0c: .. ref-code-block:: cpp :class: doxyrest-title-code-block std::size_t getInFlightCount() const ``:ref:`clear() ``` resets this count even though invalidated underlying operations may still finish; those stale completions are ignored and do not alter the count. .. rubric:: Returns: Number of HTTP requests belonging to the cache's current epoch. .. index:: pair: function; prune .. _doxid-class_e_e_1_1_u_i_1_1_web_resource_cache_1a7fbc885aecd9000e30f4230c5eaa92a3: .. ref-code-block:: cpp :class: doxyrest-title-code-block void prune() Removes expired entries and enforces the byte budget. Active document leases and loading entries are preserved. :ref:`UIWebView ` calls this periodically; other cache owners should provide their own maintenance point. .. index:: pair: function; clear .. _doxid-class_e_e_1_1_u_i_1_1_web_resource_cache_1a451a694695a6e9e37c0dd88ff6eb6820: .. ref-code-block:: cpp :class: doxyrest-title-code-block void clear() Removes every entry immediately and suppresses delivery from outstanding fetches. Sessions remain valid but no longer lease entries. This does not cancel the underlying HTTP operation. A late completion is ignored using its operation identity, including when a new request has already recreated an entry with the same cache key. .. index:: pair: function; setFetcher .. _doxid-class_e_e_1_1_u_i_1_1_web_resource_cache_1afca4fac9838bf0f48fcac2a8c254ec0c: .. ref-code-block:: cpp :class: doxyrest-title-code-block void setFetcher(:ref:`Fetcher` fetcher) Installs or clears a custom HTTP fetch implementation.