-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: Remove duplicate code and improve organization in EntryPage…
… component
- Loading branch information
Showing
2 changed files
with
113 additions
and
66 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
const CACHE_KEY = 'faviconCache'; | ||
const CACHE_EXPIRATION = 10 * 60 * 1000 * 60; // 10 hours in milliseconds | ||
|
||
export const getFaviconCache = () => { | ||
if (typeof window === 'undefined' || typeof localStorage === 'undefined') { | ||
return { favicon: {} }; // Check for client-side and localStorage | ||
} | ||
const cache = localStorage.getItem(CACHE_KEY); | ||
if (cache) { | ||
const parsedCache = JSON.parse(cache); | ||
if (Date.now() - parsedCache.timestamp < CACHE_EXPIRATION) { | ||
return parsedCache.data; | ||
} | ||
} | ||
return { favicon: {} }; | ||
}; | ||
|
||
export const setFaviconCache = (data: any) => { | ||
if (typeof window === 'undefined' || typeof localStorage === 'undefined') | ||
return; // Check for client-side and localStorage | ||
const cache = { | ||
timestamp: Date.now(), | ||
data, | ||
}; | ||
localStorage.setItem(CACHE_KEY, JSON.stringify(cache)); | ||
}; | ||
|
||
export const appendFaviconToCache = (query: string, url: any) => { | ||
const cache = getFaviconCache(); | ||
|
||
cache.favicon[query] = url; | ||
|
||
setFaviconCache(cache); | ||
}; | ||
|
||
export const invalidateFaviconFromCache = (query: string) => { | ||
const cache = getFaviconCache(); | ||
|
||
delete cache.favicon[query]; | ||
|
||
setFaviconCache(cache); | ||
}; | ||
|
||
export const clearFaviconCache = () => { | ||
localStorage.removeItem(CACHE_KEY); | ||
}; |