generated from ita-social-projects/DevTemplate
-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1405 from ita-social-projects/feature/issue-cache…
…-control Feature/issue cache control
- Loading branch information
Showing
6 changed files
with
106 additions
and
156 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
This file was deleted.
Oops, something went wrong.
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,35 @@ | ||
/* eslint-disable no-underscore-dangle */ | ||
import { Component, useEffect, useState } from 'react'; | ||
|
||
const WithClearCache: React.FC<{ children: React.ReactNode }> = ({ children }) => { | ||
const [isLatestBuildDate, setIsLatestBuildDate] = useState<boolean>(false); | ||
|
||
const refreshCacheAndReload = () => { | ||
if (caches) { | ||
caches.keys().then((names) => { | ||
for (const name of names) { | ||
caches.delete(name); | ||
} | ||
}); | ||
console.log("Cache is cleared") | ||
} | ||
window.location.reload(); | ||
}; | ||
|
||
useEffect(() => { | ||
const localVersion = localStorage.getItem('VERSION'); | ||
const isVersionMatches = localVersion === window._env_.VERSION; | ||
setIsLatestBuildDate(isVersionMatches); | ||
if (!isVersionMatches) { | ||
localStorage.setItem('VERSION', window._env_.VERSION); | ||
refreshCacheAndReload(); | ||
} | ||
}, []); | ||
|
||
if (isLatestBuildDate) { | ||
return children; | ||
} | ||
return null; | ||
}; | ||
|
||
export default WithClearCache; |
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