rename lowmem cache to disk cache
This commit is contained in:
parent
0918b210ea
commit
141b5b257c
4 changed files with 9 additions and 8 deletions
6
src/cache/disk_cache.rs
vendored
6
src/cache/disk_cache.rs
vendored
|
@ -17,7 +17,7 @@ use tokio_stream::wrappers::ReceiverStream;
|
|||
|
||||
use super::{BoxedImageStream, Cache, CacheError, CacheKey, CacheStream, ImageMetadata};
|
||||
|
||||
pub struct LowMemCache {
|
||||
pub struct DiskCache {
|
||||
disk_path: PathBuf,
|
||||
disk_cur_size: AtomicU64,
|
||||
db_update_channel_sender: Sender<DbMessage>,
|
||||
|
@ -28,7 +28,7 @@ enum DbMessage {
|
|||
Put(Arc<PathBuf>, u32),
|
||||
}
|
||||
|
||||
impl LowMemCache {
|
||||
impl DiskCache {
|
||||
/// Constructs a new low memory cache at the provided path and capaci ty.
|
||||
/// This internally spawns a task that will wait for filesystem
|
||||
/// notifications when a file has been written.
|
||||
|
@ -137,7 +137,7 @@ async fn db_listener(
|
|||
}
|
||||
|
||||
#[async_trait]
|
||||
impl Cache for LowMemCache {
|
||||
impl Cache for DiskCache {
|
||||
async fn get(
|
||||
&self,
|
||||
key: &CacheKey,
|
||||
|
|
5
src/cache/mem_cache.rs
vendored
5
src/cache/mem_cache.rs
vendored
|
@ -2,7 +2,7 @@ use std::path::PathBuf;
|
|||
use std::sync::atomic::{AtomicU64, Ordering};
|
||||
use std::sync::Arc;
|
||||
|
||||
use crate::cache::LowMemCache;
|
||||
use crate::cache::DiskCache;
|
||||
|
||||
use super::{BoxedImageStream, Cache, CacheKey, CacheStream, ImageMetadata, MemStream};
|
||||
use async_trait::async_trait;
|
||||
|
@ -13,6 +13,7 @@ use tokio::sync::mpsc::{channel, Sender};
|
|||
use tokio::sync::Mutex;
|
||||
|
||||
/// Memory accelerated disk cache. Uses an LRU in memory to speed up reads.
|
||||
///
|
||||
pub struct MemoryLruCache {
|
||||
inner: Arc<Box<dyn Cache>>,
|
||||
cur_mem_size: AtomicU64,
|
||||
|
@ -29,7 +30,7 @@ impl MemoryLruCache {
|
|||
) -> Arc<Box<dyn Cache>> {
|
||||
let (tx, mut rx) = channel(100);
|
||||
let new_self = Arc::new(Box::new(Self {
|
||||
inner: LowMemCache::new(disk_max_size, disk_path).await,
|
||||
inner: DiskCache::new(disk_max_size, disk_path).await,
|
||||
cur_mem_size: AtomicU64::new(0),
|
||||
mem_cache: Mutex::new(LruCache::unbounded()),
|
||||
master_sender: tx,
|
||||
|
|
2
src/cache/mod.rs
vendored
2
src/cache/mod.rs
vendored
|
@ -17,7 +17,7 @@ use tokio::io::BufReader;
|
|||
use tokio::sync::mpsc::Sender;
|
||||
use tokio_util::codec::{BytesCodec, FramedRead};
|
||||
|
||||
pub use disk_cache::LowMemCache;
|
||||
pub use disk_cache::DiskCache;
|
||||
pub use fs::UpstreamError;
|
||||
pub use mem_cache::MemoryLruCache;
|
||||
|
||||
|
|
|
@ -12,7 +12,7 @@ use std::{num::ParseIntError, sync::atomic::Ordering};
|
|||
use actix_web::rt::{spawn, time, System};
|
||||
use actix_web::web::{self, Data};
|
||||
use actix_web::{App, HttpServer};
|
||||
use cache::{Cache, LowMemCache};
|
||||
use cache::{Cache, DiskCache};
|
||||
use clap::Clap;
|
||||
use config::CliArgs;
|
||||
use log::{debug, error, warn, LevelFilter};
|
||||
|
@ -126,7 +126,7 @@ async fn main() -> Result<(), std::io::Error> {
|
|||
});
|
||||
|
||||
let cache: Arc<Box<dyn Cache>> = if low_mem_mode {
|
||||
LowMemCache::new(disk_quota, cache_path.clone()).await
|
||||
DiskCache::new(disk_quota, cache_path.clone()).await
|
||||
} else {
|
||||
MemoryLruCache::new(disk_quota, cache_path.clone(), memory_max_size).await
|
||||
};
|
||||
|
|
Loading…
Reference in a new issue