add preload cache, need remove PreloadBuffer

This commit is contained in:
YouROK
2021-07-11 17:13:57 +03:00
parent 4672e39e6f
commit df1ac382da
2 changed files with 21 additions and 6 deletions

View File

@@ -32,10 +32,12 @@ export default function PrimarySettingsComponent({
settings, settings,
inputForm, inputForm,
cachePercentage, cachePercentage,
preloadCachePercentage,
cacheSize, cacheSize,
isProMode, isProMode,
setCacheSize, setCacheSize,
setCachePercentage, setCachePercentage,
setPreloadCachePercentage,
updateSettings, updateSettings,
}) { }) {
const { t } = useTranslation() const { t } = useTranslation()
@@ -94,10 +96,17 @@ export default function PrimarySettingsComponent({
inputMax={100} inputMax={100}
/> />
<FormControlLabel <SliderInput
control={<Switch checked={!!PreloadBuffer} onChange={inputForm} id='PreloadBuffer' color='secondary' />} isProMode={isProMode}
label={t('SettingsDialog.PreloadBuffer')} title={t('SettingsDialog.PreloadCache')}
value={preloadCachePercentage}
setValue={setPreloadCachePercentage}
sliderMin={0}
sliderMax={100}
inputMin={0}
inputMax={100}
/> />
</div> </div>
{UseDisk ? ( {UseDisk ? (

View File

@@ -27,6 +27,7 @@ export default function SettingsDialog({ handleClose }) {
const [selectedTab, setSelectedTab] = useState(0) const [selectedTab, setSelectedTab] = useState(0)
const [cacheSize, setCacheSize] = useState(32) const [cacheSize, setCacheSize] = useState(32)
const [cachePercentage, setCachePercentage] = useState(40) const [cachePercentage, setCachePercentage] = useState(40)
const [preloadCachePercentage, setPreloadCachePercentage] = useState(0)
const [isProMode, setIsProMode] = useState(JSON.parse(localStorage.getItem('isProMode')) || false) const [isProMode, setIsProMode] = useState(JSON.parse(localStorage.getItem('isProMode')) || false)
useEffect(() => { useEffect(() => {
@@ -40,6 +41,7 @@ export default function SettingsDialog({ handleClose }) {
const sets = JSON.parse(JSON.stringify(settings)) const sets = JSON.parse(JSON.stringify(settings))
sets.CacheSize = cacheSize * 1024 * 1024 sets.CacheSize = cacheSize * 1024 * 1024
sets.ReaderReadAHead = cachePercentage sets.ReaderReadAHead = cachePercentage
sets.PreloadCache = preloadCachePercentage
axios.post(settingsHost(), { action: 'set', sets }) axios.post(settingsHost(), { action: 'set', sets })
} }
@@ -65,14 +67,15 @@ export default function SettingsDialog({ handleClose }) {
setSettings(sets) setSettings(sets)
} }
const { CacheSize, ReaderReadAHead } = settings || {} const { CacheSize, ReaderReadAHead, PreloadCache } = settings || {}
useEffect(() => { useEffect(() => {
if (!CacheSize || !ReaderReadAHead) return if (!CacheSize || !ReaderReadAHead || !PreloadCache) return
setCacheSize(CacheSize) setCacheSize(CacheSize)
setCachePercentage(ReaderReadAHead) setCachePercentage(ReaderReadAHead)
}, [CacheSize, ReaderReadAHead]) setPreloadCachePercentage(PreloadCache)
}, [CacheSize, ReaderReadAHead, PreloadCache])
const updateSettings = newProps => setSettings({ ...settings, ...newProps }) const updateSettings = newProps => setSettings({ ...settings, ...newProps })
const handleChange = (_, newValue) => setSelectedTab(newValue) const handleChange = (_, newValue) => setSelectedTab(newValue)
@@ -134,10 +137,12 @@ export default function SettingsDialog({ handleClose }) {
settings={settings} settings={settings}
inputForm={inputForm} inputForm={inputForm}
cachePercentage={cachePercentage} cachePercentage={cachePercentage}
preloadCachePercentage={preloadCachePercentage}
cacheSize={cacheSize} cacheSize={cacheSize}
isProMode={isProMode} isProMode={isProMode}
setCacheSize={setCacheSize} setCacheSize={setCacheSize}
setCachePercentage={setCachePercentage} setCachePercentage={setCachePercentage}
setPreloadCachePercentage={setPreloadCachePercentage}
updateSettings={updateSettings} updateSettings={updateSettings}
/> />
</TabPanel> </TabPanel>
@@ -161,6 +166,7 @@ export default function SettingsDialog({ handleClose }) {
onClick={() => { onClick={() => {
setCacheSize(defaultSettings.CacheSize) setCacheSize(defaultSettings.CacheSize)
setCachePercentage(defaultSettings.ReaderReadAHead) setCachePercentage(defaultSettings.ReaderReadAHead)
setPreloadCachePercentage(defaultSettings.PreloadCache)
updateSettings(defaultSettings) updateSettings(defaultSettings)
}} }}
color='secondary' color='secondary'