← All articlesMobile applications

How to Define Caching Rules for WebView Pages and Android Temporary Files

When configuring caching in an Android app, start by listing the copies of sensitive data. A document page in WebView and a temporary file created by the app itself need separate rules and checks. This article explains how to build that table, check server headers and directory selection, and specify where clearCache belongs in a workflow involving a JavaScript interface. All examples below are fictional and use synthetic documents you own.

Describe each copy first

For developers, the task is to connect each copy to a specific storage rule. For product owners, it is to establish why that copy is needed and what behavior is acceptable. Avoid relying on a broad statement such as ‘sensitive data is not cached’: it makes the page and the file difficult to verify separately.

In a wholly fictional app called ‘Test Archive,’ a user opens a synthetic document called ‘Sample Certificate 042.’ Suppose the project includes a viewing page in WebView and a separate temporary file copy. Give them separate rows in the table, even if both display the same document.

  • Table fields: page or file, sensitivity, purpose of the copy, actual storage location, caching rule, cleanup event, and verification method.
  • Certificate page: sensitive; purpose—viewing; project requirement—server-directed prohibition on caching; verification—the header actually received and observations when reopening the page.
  • Temporary certificate copy: sensitive; purpose—reading as provided for by the app; project requirement—an internal directory; verification—the actual write path and expected contents.

Separate trust boundaries and responsibilities

Server headers can specify that particular content should not be cached. Check the storage location of a separate temporary file independently: a caching prohibition for the page does not confirm that no file copy exists. The table should show both areas of responsibility—the server response rule and the app’s storage choice.

For private user data, the documentation recommends internal storage isolated for each app. The internal cache directory returned by getCacheDir() is private to the app; for the external cache directory, the documentation explicitly warns that files have no security protection. This distinction defines the boundary when choosing where to store a sensitive copy.

Check the sensitive page’s header

For the ‘Sample Certificate 042’ page, set a requirement to receive Cache-Control: no-store. The no-store directive indicates that particular content should not be cached. Check the actual response from your own test server so you can compare the requirement with the observed result.

The check proposed here is an original editorial test design, not an official Android procedure. Open the sensitive page, record the header received, then open it again and record its behavior. Add a positive control: a nonsensitive page you own containing known test text. It should load and display that exact text. A single successful HTTP response does not confirm that the caching requirement has been met.

Check the temporary file’s actual directory

For the sensitive temporary copy, set a project requirement for internal storage, for example in the directory returned by getCacheDir(). The app does not need to request permission to access its own files in internal storage. However, directory privacy alone does not define how long the copy is retained: specify the required cleanup event separately.

As part of the editorial test design, create your own synthetic file and record the actual write path. The positive control is the app successfully reading the expected text, ‘Sample Certificate 042.’ Check every supported directory-selection branch, including those for different file sizes. The project’s acceptance criterion is that none of these branches moves the sensitive copy to external cache.

Specify exactly where clearCache belongs in the workflow

In the context of sensitive data and a WebView JavaScript interface, the documentation suggests considering clearCache before using the interface. Tie this recommendation to the relevant workflow. It does not describe a complete cleanup of app data.

If the fictional ‘Test Archive’ includes such an interface and the team chooses to call clearCache, record its place in the sequence of actions. The editorial check is to first confirm that your own document loads normally, then record that the call executes before the interface is used, and separately describe subsequent behavior. The criterion here is a confirmed sequence of calls and observations, without promising the removal of cookies, web storage, separate app files, or every trace of the document.

Set priorities and handle missing cache data

Make selecting an internal directory for sensitive files and checking every write branch the first priority. Next, verify the actual no-store header on sensitive pages. Then confirm the intended clearCache sequence in the JavaScript interface workflow. Assign an owner to each item and save the observed result alongside its requirement.

If the app uses external cache for nonsensitive material, account for data becoming unavailable after the storage medium is removed. The documentation requires handling this situation correctly. In the fictional project, a testable requirement could be that the app displays its intended state for unavailable material. The product team determines exactly what that state looks like.

Document the limits of verification

The result should be a completed table with confirmed headers, file paths, read results, and the sequence of intended calls. The presence of no-store and observations after clearCache do not prove that all local traces are absent. Detailed parameters and the full scope of clearCache require separate primary documentation; the checks described here provide no statistical security guarantees.

For a website or the web portion of a product, you can start with a free CheckMyApp audit. The documented requirements will help guide discussion of server responses and the scope of web verification; checks of Android app directories and calls should be included separately in the mobile team’s work.

Sources and documentation

  1. WebView – Native bridges
  2. Improve your app's security
CheckMyApp

Check your application’s security.

Enter your web application address and email. Get a free preliminary report and choose the depth of analysis.

Check for free