Two Simple Rules for HTTP Caching

本文介绍了优化HTTP缓存的两个简单规则:不要缓存HTML,其他资源永久缓存。详细解释了如何通过设置Expires头、Cache-Control头以及Last-Modified头来实现资源的有效缓存,同时避免了HTML被缓存的问题,以确保网站内容的及时更新。

Two Simple Rules for HTTP Caching


In practice, you only need two settings to optimize caching:

  1. Don’t cache HTML
  2. Cache everything else forever

“Wooah…hang on!”,we hear you say.“Cache all my scripts and imagesforever?

Yes, that’s right. You don’t need anything else in between. Caching indefinitely is fine as long as you don’t allow your HTML to be cached.

“But what about if I need to issue code patches to my JavaScript? I can’t allowbrowsers to hold on to all my images either. I often need to update those as well.”

Simple – just change the URL of the item in your HTML and it will bypass the existing entry in the cache.

In practice, caching ‘forever’ typically means setting anExpiresheader value ofSun, 17-Jan-2038 19:14:07 GMTsince that’s the maximum value supported by the 32 bit Unix time/date format. If you’re using IIS6 you’ll find that the UI won’t allow anything beyond 31-Dec-2035. The advantage of setting long expiry dates is that the content can be read from the local browser cache whenever the user revisits the web page or goes to another page thatuses the same images, script or CSS files.

You’ll see long expiry dates like this if you look at a Google web page with HttpWatch. For example, here are the response headers used for the main Google logo on the home page:

Google Expires header

If Google needs to change the logo for a special occasion like Halloween they just change the name of the file in the page’s HTML to something like halloween2007.gif.

The diagram below shows how a JavaScript file is loaded into the browser cache on the first visit to a web page:

Accessing page with empty cache

On any subsequent visits the browser only has to fetch the page’s HTML:

Read from cache

The JavaScript file can be read directly from the browser cache on the user’s hard disk. This avoids a network round trip and is typically 100 to 1000 times faster than downloading the file over a broadband connection.

The key to this caching scheme is to keep tight control over your HTML as it holds the references to everything else on your web site. One way to do this is to ensure that your pages have aCache-Control: no-cacheheader. This will prevent any caching of the HTML and will ensure the browser requests the page’s HTML every time.

If you do this, you can update any content on the page just by changing the URL that refers to it in the HTML. The old version will still be in the browser’s cache, but the updated version will be downloaded because of the modified URL.

For instance, if you had a file called topMenu.js and you fixed some bugs in it, you might rename the file topMenu-v2.js to force it to be downloaded:

Force update with new file name

Now this is all very well, but whenever there’s a discussion of longerexpiration times, the marketing people get very twitchy and concerned that they won’t be able to re-brand a site if stylesheets and images are cached for long periods of time.

In fact, choosing an expirationtime of anything other than zero or infinite is inherently uncertain. The only way to know exactly when you can release a new version to all users simultaneously is to choose a specific time of day for your cache expiry; say midnight. It’s better to set indefinite caching on all your page-linked items so that you get the maximum amount of caching, and then force updates as required.

Now, by this point, you might have the marketing types on board but you’ll be losing the developers. The developers by now are seeing all the extra work involved in changing the filenames of all their CSS, javascript and images both in their source controlled projects and in their deployment scripts.

So here’s the icing on the cake; you don’t actuallyneedto change the filename, just the URL. A simple way to do this is to append a query string parameter onto the end of the existing URL when the resource has changed.

Here’s the previous example that updated a JavaScript file. The difference this time is that it uses a query string parameter ‘v2′ to bypass the existing cache entry:

Force update with query string

The web server will simply ignore the query string parameter unless you have chosen to do anything with it programmatically.

There’s one final optimization you can make. TheCache-Control: no-cacheresponse header works well for dynamic pages as it ensures that pages will always be refreshed from the server; even when pressing the Back button. However, for HTML that changes less frequently it is better to use theLast-Modifiedheader instead. This will avoid a complete download of the page’s HTML, if it has not changed since it was last cached by the browser.

TheLast-Modifiedheader is added automatically by IIS for static HTML files and can be added programmatically in dynamic pages (e.g. ASPX and PHP). When this header is present, the browser will revalidate the local, cached copy of an HTML page in each new browser session. If the page is unchanged the web server returns a304 Not Modifiedresponse indicating the browser can use the cached version of the page.

So to summarize:

  1. Don’t cache HTML
    • UseCache-Control: no-cachefor dynamic HTML pages
    • Use theLast-Modifiedheader with the current file time for static HTML
  2. Cache everything else forever
    • For all other file types set anExpiresheader to the maximum future date your web server will allow
  3. Modify URLs by appending a query string in your HTML to any page element you wish to ‘expire’ immediately.

III. PROBLEM FORMULATION VLN-Zero leverages a VLM to enable rapid exploration and adaptation without the need to fine-tune or perform multi-shot inference. The VLM is informed via textual constraints and guides exploration to build a scene graph of the environment. During deployment, this scene graph, visual observations, and cached policies are consumed by the VLM to enable efficient execution while enforcing user-specified constraints. Formally, we consider an autonomous agent S equipped with sensors such as a camera and an inertial measurement unit (IMU) along with compute offering API access to call a VLM. The agent operates under a set Φ of user provided constraints, expressed in natural language (e.g., “Do not collide with pedestrians”), which must hold during both exploration and execution. From the camera, the agent obtains first-person images as visual observations o. A pre trained VLM MVL serves as a reasoning engine with both image-understanding and text-reasoning capabilities. The input to MVL consists of the tuple (S,Φ,o). A call to MVL yields the outputs: • an action a to be executed by the agent, and • a scene graph GS during exploration, represented as a top-down map of the environment, capturing traversable areas, obstacles, and landmarks used for downstream navigation. We formalize two central problems for this work. a) Problem 1- Rapid Exploration: We want to design a prompting strategy for MVL that enables the autonomous agent to efficiently explore a novel environment and facilitate construction of a top-down scene graph GS as a byproduct of the navigation actions taken. The exploration process should be completed within a limited time span of 1 hour, producing a scene graph sufficient to support navigation. b) Problem 2- Deployment: Construct a planner P such that P(Φ,o,Tp,GS) = a, where Tp is a textual task prompt describing the agent’s expected navigation goal. The planner generates an action a that should (i) satisfy Φ, and (ii) contribute to efficiently achieving the navigation objective in Tp. Importantly, the planner should adapt to the new environment by reasoning over the scene graph GS obtained during exploration, without requiring fine-tuning. IV. VLN-ZERO: ZERO-SHOT VLM NAVIGATION We develop a framework, VLN-Zero, that consists of two phases: an exploration phase, where the autonomous agent leverages a VLM to rapidly explore a new environment and construct a top-down scene graph, and a deployment phase, where the planner uses this scene graph to adapt to new tasks under user-specified constraints without fine tuning. The deployment phase further integrates a high-level landmark-to-landmark cache that reuses previously validated plans to accelerate execution. Prompt: Generate simple step-by-step navigation instructions for a robot exploring an unknown environment. The robot can only perform the following actions: move forward, turn left, turn right, and stop. Constraints:- Use only the allowed actions.- Return a single action.- Stop when exploration of the visible environment is complete or when further movement is unsafe.- Avoid visiting explored areas <Scene Graph> <Visual Observation> Response: <One of the four actions> Fig. 2: Prompt Te used for guiding MVL during the explo ration phase. Algorithm 1 VLN-Zero: VLM-Guided Exploration Require: Agent S, constraints Φ, VLM MVL Ensure: Scene graph GS 1: Initialize empty scene graph GS ← ∅ 2: t ← 0 3: while t < exploration time limit do 4: 5: 6: 7: 8: Observe environment: o ← sensor data() (a, G′ S) ← MVL(S,Φ,o) Execute action: S.execute(a) Update scene graph: GS ← GS ∪G′ S t ←t+1 9: end while 10: return GS A. Rapid Exploration The goal of the exploration phase is to enable the au tonomous agent S to rapidly adapt to an unseen environment without retraining. Instead of relying on traditional pre trained planner that may not generalize, we leverage the multimodal reasoning ability of the VLM MVL to jointly interpret user constraints Φ and visual observations o. The VLM produces exploratory high-level actions, e.g., move straight or turn right, that safely guide the robot through the environment used to incrementally construct an interpretable scene graph GS in the form of a top-down map using odometry from an IMU. At each step of the exploration process, the autonomous agent (i.e., robot) obtains a new observation o through its visual sensors. The tuple (S,Φ,o) is sent to MVL via an API call. The model outputs an action a, which is executed by the robot, and a partial update G′ S is made to the scene graph. Prompt: Move from your start location to a goal location using the provided top down scene graph and camera view. <Constraints> <Scene Graph>- SQUARE: Your starting position.- BLUE ARROW: Your current position & heading.- BLUE LINE: Your trajectory so far.- GRAY AREAS: Navigable floor where you can walk.- WHITE AREAS: Obstacles or walls you cannot walk through. <Visual Observation> NAVIGATION RULES:- Use a top-down scene graph to determine the direction to move in. ...... Response: <One of the four actions> Fig. 3: Prompt Tp used for guiding the planner P during the deployment phase. Text in brackets (<>) are parameterized, while the others are fixed meta prompts. We present a scene graph used in this prompt in Fig. 8. The global scene graph GS is updated constantly by merging G′ S into the existing representation. During this process, we group objects that are semantically relevant to landmarks such as “living room” or “kitchen” to append semantic tags to the scene graph. By prompting the VLM with Φ, unsafe behaviors (e.g., entering restricted areas or colliding with obstacles) are avoided during exploration. We present the input prompt to the VLM that guides the exploration, as shown in Fig. 2. We present this exploration process in Algorithm 1. This exploration loop continues until either the exploration time budget is exhausted or sufficient coverage of the environment has been achieved. To detect whether the exploration phase achieves sufficient coverage, we monitor the top-down scene graph for two structural indicators: (i) the loop closure of the periphery, indicating that the robot has traced the boundaries of the accessible region, and (ii) the absence of large unexplored empty areas within the mapped region. We present an example of the constructed scene graph with the exploration route in Fig. 1. Once both conditions are satisfied, we consider the environment sufficiently explored, and the final scene graph GS is ready for deployment. In practice, we enforce a 1 hour limit, which balances the need for rapid deployment with the completeness of the resulting scene graph. The final scene graph GS serves as the structured foundation for downstream navigation in the Algorithm 2 VLN-Zero: Cached-Enabled Navigation Require: Prompt Tp, location ℓ, scene graph GS, cache C Ensure: Action a 1: if (Tp) ∈ C then ▷ Check task-level cache 2: 3: τ ←C[(Tp)] a ←next action(τ,ℓ) 4: else if (T′ p,ℓ) ∈ C then 5: 6: ▷ Check subtask/location cache, where T′ p is the subtask/location-specific query τ ←C[(T′ p,ℓ)] a ←next action(τ) 7: else 8: 9: 10: 11: a ←P(Φ,o,Tp,GS) ▷ Fall back to navigation τ ←compute trajectory(a,Tp,GS) C[(Tp,ℓ)] ← τ ▷ Store subtask-level plan C[(Tp)] ← merge(C[(Tp)],τ) 12: end if 13: return a ▷ Update task plan deployment phase. B. Cache-Enabled Neurosymbolic Deployment a) Environment Adaptation Using a Scene Graph: In the deployment phase, the planner P leverages the scene graph GS constructed during exploration to adapt to the new environment without any additional training. Unlike policy based methods that require re-training, the planner adapts to the new environment by reasoning directly over the scene graph (i.e., top-down map). The planner P receives the task prompt Tp, constraints Φ, real-time observations o that in clude a first-person-view image and a top-down scene graph GS as inputs. We present a sample prompt in Fig. 3. The planner, P(Φ,o,Tp,GS), computes a constraint-compliant action that contributes to accomplishing the navigation goal by reasoning over the scene graph. For example, given the task prompt “deliver an item to the kitchen,” the planner uses GS to identify feasible trajectories, ensures that non traversable areas are excluded, and generates an action a aligned with the task objective. b) Task Execution with Caching: To accelerate real time navigation, we introduce a caching module that stores previously validated navigation trajectories. Given, VLMs do not have an explicit internalization of memory, intuitively, caching helps with both efficiency and task success proba bility. Formally, the cache C is maintained as a dictionary of the form C ={(Tp,current location ℓ) : trajectory}, where each entry associates a task prompt and the agent’s current position with a feasible trajectory that satisfies the constraints Φ, a trajectory is a set of consecutive points in the scene graph representing the relative positions in the environment. We present an example of a cached trajectory in Fig. 1. To further accelerate execution and improve reuse across tasks, we employ a hierarchical caching strategy. Instead of storing only complete trajectories for specific task–location pairs, the cache C maintains trajectories at multiple granular ities: task-level trajectories (Tp), subtask or location-specific trajectories (Tp, ℓ), and reusable fragments such as room-to room or room-to-object transitions. For example, a room-to room trajectory will be stored as {(“go to the bedroom”, ℓ =location of the main entrance): a trajectory from the main entrance to the entrance of the bedroom}. And a sample object-to-object transition is {(“go to bed”, ℓ =entrance of the bedroom): a trajectory from the bedroom entrance to the bed}. This hierarchical structure enables the planner to compose cached sub-trajectories to construct feasible trajectories for new tasks, even when the exact query has not been encoun tered before. During execution, the planner first checks whether the cache already contains a task-level trajectory for Tp. If available, the next action is directly extracted from this stored plan instead of calling the VLM. If not, the planner f irst decomposes the task prompt into a set of subtask- or location-specific prompts. In practice, we use a VLM as our planner backbone and query it for task decomposition. Then, the planner queries the subtask or location-level cache, retrieving smaller route segments that can be reused. When neither level of cache contains a matching entry, the planner falls back to computing a new trajectory by reasoning over the scene graph GS. We illustrate the overall process in Algorithm 2, which demonstrates how hierarchical caching balances efficiency and adaptability. In summary, our deployment phase high lights the two complementary modes of operation: (i) fast retrieval of validated trajectories when available, and (ii) adaptive reasoning over the scene graph when new task queries are encountered. This dual mechanism ensures that the planner can adapt to novel navigation goals in unfamiliar environments while maintaining efficiency and adaptability.详细解释一下
10-23
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值