File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -35,12 +35,26 @@ const initPHPSearch = async (language) => {
3535 return data ;
3636 } ;
3737
38+ const cleanupOld = async ( ) => {
39+ // Previously used cache key
40+ const key = `search-${ language } ` ;
41+ const oldCache = window . localStorage . getItem ( key ) ;
42+ if ( ! oldCache ) {
43+ return ;
44+ }
45+
46+ // Clear is used to clear all cached languages at the same time
47+ // This reduces the chances of hitting quota
48+ window . localStorage . clear ( ) ;
49+ }
50+
3851 /**
3952 * Fetch the search index.
4053 *
4154 * @returns {Promise<Array> } The search index.
4255 */
4356 const fetchIndex = async ( ) => {
57+ await cleanupOld ( ) ;
4458 const key = `search2-${ language } ` ;
4559 let items ;
4660 if ( language === 'local' ) {
@@ -60,7 +74,7 @@ const initPHPSearch = async (language) => {
6074 } catch ( e ) {
6175 // Local storage might be full, or other error.
6276 // Just continue without caching.
63- console . error ( "Failed to cache search index" , e ) ;
77+ console . info ( "Failed to cache search index" , e ) ;
6478 }
6579 }
6680
You can’t perform that action at this time.
0 commit comments