Skip to content

Search: Index Caching Issues #1593

@AllenJB

Description

@AllenJB

The way the search caches indexes is, in my opinion, not ideal.

Background

The current search feature caches the indexes in localStorage, using a unique key for each language.

Related code:

const lookupIndexCache = () => {
(the first 4 functions, but mostly the first 2, here deal with loading and caching the indexes)

The search indexes are ~2.1 MB (.json file size) and localStorage quota is (generally) 5MB according to https://developer.mozilla.org/en-US/docs/Web/API/Storage_API/Storage_quotas_and_eviction_criteria

The current search uses localStorage and caches the indexes with a key for each specific language.

This means that if a user uses the manual in multiple languages, they can store at most 2 before hitting the localStorage quota.

This doesn't stop search working in further languages - the indexes of further visited languages just don't get cached.

However, if a user visits a language, then never returns to it, the indexes for that language are never considered for deletion, and data in localStorage never expires otherwise (unless the user manually clears their data, or the browser decides to delete data from a site not recently visited - I don't know the specifics of browser behavior in this regard)

This means that if the user regularly uses php.net, that (old) unused data remains in localStorage forever, preventing the storage of further data. At the moment, based on a quick search of the web-php repo, this is just other search indexes, but could be used for other functionality in the future.

Alternative Options

I'm not very familiar with explicitly caching data client-side, but based on some (relatively quick) research I think that if this functionality is to be retained, it should be rewritten to use either Cache API or OPFS. These seem to be designed to do exactly what the search is using localStorage for, and the storage quotas are much larger.

An advantage of going with OPFS would be that it would be trivial to manage cached indexes for all languages (listing them in a directory) and deleting unused ones, if that's desirable.

The other alternative would be to get rid of JS caching altogether and just let the browser handle caching as with any other web request.

Does anyone else have thoughts on this?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions