mirror of
https://github.com/jeffvli/feishin.git
synced 2026-05-15 13:00:25 +02:00
add manual garbage collection
This commit is contained in:
@@ -0,0 +1,42 @@
|
||||
import isElectron from 'is-electron';
|
||||
import { useEffect, useRef } from 'react';
|
||||
import { useLocation } from 'react-router';
|
||||
|
||||
const GARBAGE_COLLECTION_INTERVAL = 1000 * 60 * 5;
|
||||
|
||||
export const useGarbageCollection = () => {
|
||||
const intervalIdRef = useRef<NodeJS.Timeout | null>(null);
|
||||
|
||||
// Clear the cache on an interval
|
||||
useEffect(() => {
|
||||
if (!isElectron()) {
|
||||
return;
|
||||
}
|
||||
|
||||
intervalIdRef.current = setInterval(() => {
|
||||
window.api?.utils?.forceGarbageCollection?.();
|
||||
}, GARBAGE_COLLECTION_INTERVAL);
|
||||
|
||||
return () => {
|
||||
if (intervalIdRef.current) {
|
||||
clearInterval(intervalIdRef.current);
|
||||
}
|
||||
};
|
||||
}, []);
|
||||
|
||||
const location = useLocation();
|
||||
|
||||
// Clear the cache when the location changes
|
||||
useEffect(() => {
|
||||
if (!isElectron()) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Clear the interval when the location changes
|
||||
if (intervalIdRef.current) {
|
||||
clearInterval(intervalIdRef.current);
|
||||
}
|
||||
|
||||
window.api?.utils?.forceGarbageCollection?.();
|
||||
}, [location]);
|
||||
};
|
||||
Reference in New Issue
Block a user