Hacktoberfest 2026: những issue maintainer đã đánh dấu cho tháng Mười, đang mở và phù hợp người mới. Xem issue Hacktoberfest

Search: Index Caching Issues

Đang mở
#1,593 1 bình luận 0 reaction 0 người được giao Xem trên GitHub

Chưa có ai nhận issue này.

Đánh giá

Độ khó
5/5
Thời gian dự kiến
Hơn một tuần
Mức phù hợp với người mới
25/100
Loại issue
Tái cấu trúc
Độ rõ ràng
Cần làm rõ
Mức độ hoạt động
Đình trệ
Công nghệ
javascript
Lĩnh vực
search

Hướng nghiên cứu

Đọc js/search.js, đặc biệt là bốn hàm đầu tiên và hai hàm đầu tiên tải và lưu vào bộ nhớ đệm các chỉ mục ngôn ngữ trong localStorage. So sánh hành vi lưu vào bộ nhớ đệm theo từng ngôn ngữ hiện tại với các tùy chọn Cache API, OPFS hoặc bộ nhớ đệm do trình duyệt quản lý được mô tả trong issue; việc hoàn thành phụ thuộc vào việc thống nhất và triển khai một chiến lược thay thế xử lý các chỉ mục không được sử dụng.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Mô tả

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: https://github.com/php/web-php/blob/e7cfbe98203d93e00aac7c0d159d7c9c3d4faadd/js/search.js#L19 (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?

Ngôn ngữ chính
PHP
Star
1.1k
Fork
641
Merge trung bình
1 ngày 11 giờ
Pull request đã merge (30 ngày)
19

Hướng dẫn đóng góp

Mở hướng dẫn đóng góp

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Issue khác của php/web-php

Tất cả issue của php/web-php

Issue tương tự

Thêm issue về PHP

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.