mirror of
https://github.com/venera-app/venera.git
synced 2025-09-27 07:47:24 +00:00
fix cache
This commit is contained in:
@@ -1,5 +1,3 @@
|
|||||||
import 'dart:io';
|
|
||||||
|
|
||||||
import 'package:crypto/crypto.dart';
|
import 'package:crypto/crypto.dart';
|
||||||
import 'package:flutter/foundation.dart';
|
import 'package:flutter/foundation.dart';
|
||||||
import 'package:sqlite3/sqlite3.dart';
|
import 'package:sqlite3/sqlite3.dart';
|
||||||
@@ -84,9 +82,7 @@ class CacheManager {
|
|||||||
if(_currentSize != null) {
|
if(_currentSize != null) {
|
||||||
_currentSize = _currentSize! + data.length;
|
_currentSize = _currentSize! + data.length;
|
||||||
}
|
}
|
||||||
if(_currentSize != null && _currentSize! > _limitSize){
|
checkCacheIfRequired();
|
||||||
await checkCache();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<CachingFile> openWrite(String key) async{
|
Future<CachingFile> openWrite(String key) async{
|
||||||
@@ -123,6 +119,12 @@ class CacheManager {
|
|||||||
|
|
||||||
bool _isChecking = false;
|
bool _isChecking = false;
|
||||||
|
|
||||||
|
void checkCacheIfRequired() {
|
||||||
|
if(_currentSize != null && _currentSize! > _limitSize){
|
||||||
|
checkCache();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
Future<void> checkCache() async{
|
Future<void> checkCache() async{
|
||||||
if(_isChecking){
|
if(_isChecking){
|
||||||
return;
|
return;
|
||||||
@@ -279,6 +281,7 @@ class CachingFile{
|
|||||||
CacheManager()._db.execute('''
|
CacheManager()._db.execute('''
|
||||||
INSERT OR REPLACE INTO cache (key, dir, name, expires) VALUES (?, ?, ?, ?)
|
INSERT OR REPLACE INTO cache (key, dir, name, expires) VALUES (?, ?, ?, ?)
|
||||||
''', [key, dir, name, DateTime.now().millisecondsSinceEpoch + 7 * 24 * 60 * 60 * 1000]);
|
''', [key, dir, name, DateTime.now().millisecondsSinceEpoch + 7 * 24 * 60 * 60 * 1000]);
|
||||||
|
CacheManager().checkCacheIfRequired();
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<void> cancel() async{
|
Future<void> cancel() async{
|
||||||
|
Reference in New Issue
Block a user