Compare commits

..

No commits in common. "7f16e697e6c24c7ab701aa08d79590d9d65d4cf6" and "a70f4bfdc3ac80e7e89cddd1802af00201fd7d73" have entirely different histories.

2 changed files with 18 additions and 28 deletions

23
src/cache/fs.rs vendored
View file

@ -91,21 +91,14 @@ pub(super) async fn read_file(
return None;
}
let header = if let Some(header) = Header::from_slice(&header_bytes) {
header
} else {
warn!("Found file, but encrypted header was invalid. Assuming corrupted!");
return None;
};
let secret_stream = if let Ok(stream) = SecretStream::init_pull(&header, key) {
stream
} else {
warn!("Failed to init secret stream with key and header. Assuming corrupted!");
return None;
};
Box::pin(EncryptedDiskReader::new(file, secret_stream))
Box::pin(EncryptedDiskReader::new(
file,
SecretStream::init_pull(
&Header::from_slice(&header_bytes).expect("failed to get header"),
key,
)
.expect("Failed to initialize decryption kesy"),
))
} else {
Box::pin(file)
};

23
src/cache/mem.rs vendored
View file

@ -74,24 +74,22 @@ impl InternalMemoryCache for Lru {
/// Memory accelerated disk cache. Uses the internal cache implementation in
/// memory to speed up reads.
pub struct MemoryCache<MemoryCacheImpl, ColdCache> {
inner: ColdCache,
pub struct MemoryCache<InternalCacheImpl, InnerCache> {
inner: InnerCache,
cur_mem_size: AtomicU64,
mem_cache: Mutex<MemoryCacheImpl>,
mem_cache: Mutex<InternalCacheImpl>,
master_sender: Sender<(CacheKey, Bytes, ImageMetadata, u64)>,
}
impl<MemoryCacheImpl, ColdCache> MemoryCache<MemoryCacheImpl, ColdCache>
where
MemoryCacheImpl: 'static + InternalMemoryCache,
ColdCache: 'static + Cache,
impl<InternalCacheImpl: 'static + InternalMemoryCache, InnerCache: 'static + Cache>
MemoryCache<InternalCacheImpl, InnerCache>
{
pub async fn new(inner: ColdCache, max_mem_size: u64) -> Arc<Self> {
pub async fn new(inner: InnerCache, max_mem_size: u64) -> Arc<Self> {
let (tx, mut rx) = channel(100);
let new_self = Arc::new(Self {
inner,
cur_mem_size: AtomicU64::new(0),
mem_cache: Mutex::new(MemoryCacheImpl::unbounded()),
mem_cache: Mutex::new(InternalCacheImpl::unbounded()),
master_sender: tx,
});
@ -101,7 +99,6 @@ where
let max_mem_size = max_mem_size / 20 * 19;
while let Some((key, bytes, metadata, size)) = rx.recv().await {
// Add to memory cache
// We can add first because we constrain our memory usage to 95%
new_self
.cur_mem_size
.fetch_add(size as u64, Ordering::Release);
@ -135,10 +132,10 @@ where
}
#[async_trait]
impl<MemoryCacheImpl, ColdCache> Cache for MemoryCache<MemoryCacheImpl, ColdCache>
impl<InternalCacheImpl, InnerCache> Cache for MemoryCache<InternalCacheImpl, InnerCache>
where
MemoryCacheImpl: InternalMemoryCache,
ColdCache: CallbackCache,
InternalCacheImpl: InternalMemoryCache,
InnerCache: CallbackCache,
{
#[inline]
async fn get(