FileSponge/src/main/java/org/warp/filesponge/DiskCache.java

66 lines
2.4 KiB
Java
Raw Normal View History

2021-03-07 15:50:11 +01:00
/*
* FileSponge
2023-02-28 23:11:07 +01:00
* Copyright (C) 2023 Andrea Cavalli
2021-03-07 15:50:11 +01:00
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package org.warp.filesponge;
2022-08-15 23:07:50 +02:00
import it.cavallium.dbengine.client.IBackuppable;
2022-03-02 12:38:25 +01:00
import it.cavallium.dbengine.database.ColumnUtils;
2021-03-07 15:50:11 +01:00
import it.cavallium.dbengine.database.LLDatabaseConnection;
import it.cavallium.dbengine.database.LLDictionary;
2023-02-28 23:11:07 +01:00
import it.cavallium.dbengine.database.SafeCloseable;
2021-03-07 15:50:11 +01:00
import it.cavallium.dbengine.database.UpdateMode;
2022-03-02 12:38:25 +01:00
import it.cavallium.dbengine.rpc.current.data.DatabaseOptions;
2021-03-07 15:50:11 +01:00
import java.util.List;
2021-11-11 20:27:57 +01:00
import java.util.function.Predicate;
2023-02-28 23:11:07 +01:00
import java.util.stream.Stream;
2021-03-07 15:50:11 +01:00
import reactor.util.function.Tuple2;
2021-10-19 00:28:30 +02:00
2023-07-25 12:24:10 +02:00
public interface DiskCache extends URLsDiskHandler, URLsWriter, SafeCloseable, IBackuppable {
2021-10-19 00:28:30 +02:00
2023-08-22 12:41:24 +02:00
void writeMetadataSync(URL url, Metadata metadata, boolean force);
2021-11-11 20:27:57 +01:00
2023-08-22 12:41:24 +02:00
void writeContentBlockSync(URL url, DataBlock dataBlock, boolean force);
2021-03-07 15:50:11 +01:00
2023-02-28 23:11:07 +01:00
Stream<DataBlock> requestContentSync(URL url);
2021-03-07 15:50:11 +01:00
2023-02-28 23:11:07 +01:00
DiskMetadata requestDiskMetadataSync(URL url);
2021-03-07 15:50:11 +01:00
2023-02-28 23:11:07 +01:00
Metadata requestMetadataSync(URL url);
2021-03-07 15:50:11 +01:00
2023-02-28 23:11:07 +01:00
Tuple2<Metadata, Stream<DataBlock>> requestSync(URL url);
2021-03-07 15:50:11 +01:00
2023-02-28 23:11:07 +01:00
static DiskCache open(LLDatabaseConnection databaseConnection,
String dbName,
DatabaseOptions databaseOptions,
Predicate<URL> shouldCache) {
var db = databaseConnection.getDatabase(dbName,
List.of(ColumnUtils.dictionary("file-content"), ColumnUtils.dictionary("file-metadata")),
databaseOptions
);
var dict1 = db.getDictionary("file-content", UpdateMode.ALLOW);
var dict2 = db.getDictionary("file-metadata", UpdateMode.ALLOW);
return new DiskCacheImpl(db, dict1, dict2, shouldCache);
2022-08-15 23:07:50 +02:00
}
2023-07-22 00:56:13 +02:00
static DiskCache openCustom(LLDictionary fileContent,
2023-02-28 23:11:07 +01:00
LLDictionary fileMetadata,
Predicate<URL> shouldCache) {
2023-07-22 00:56:13 +02:00
return new DiskCacheImpl(null, fileContent, fileMetadata, shouldCache);
2022-08-15 23:07:50 +02:00
}
2021-03-07 15:50:11 +01:00
}