#pragma once
#include "../cdn/memory_cache.h"
#include <array>
#include <memory>
#include <optional>
#include <vector>
namespace whiteout::storages::casc {
struct MemCacheEnabled {
mutable std::unique_ptr<MemoryCache> cache;
explicit MemCacheEnabled(std::unique_ptr<MemoryCache> c) : cache(std::move(c)) {}
MemCacheEnabled(MemCacheEnabled&&) = default;
MemCacheEnabled& operator=(MemCacheEnabled&&) = default;
static constexpr bool hasCache() noexcept {
return true;
}
std::optional<std::vector<u8>> get(const std::array<u8, 16>& key) const {
return cache->get(key);
}
std::optional<MemoryCache::CacheView> view(const std::array<u8, 16>& key) const {
return cache->view(key);
}
void put(const std::array<u8, 16>& key, const std::vector<u8>& data) const {
cache->put(key, data);
}
void flush() const {
cache->clear();
}
};
struct NoCachePolicy {
static constexpr bool hasCache() noexcept {
return false;
}
std::optional<std::vector<u8>> get(const std::array<u8, 16>&) const {
return std::nullopt;
}
std::optional<MemoryCache::CacheView> view(const std::array<u8, 16>&) const {
return std::nullopt;
}
void put(const std::array<u8, 16>&, const std::vector<u8>&) const {}
void flush() const {}
};
}