datalab_cli/commands/
cache.rs1use crate::cache::Cache;
2use crate::error::Result;
3use clap::{Args, Subcommand};
4
5#[derive(Subcommand, Debug)]
6pub enum CacheCommand {
7 Clear(ClearArgs),
9 Stats,
11}
12
13#[derive(Args, Debug)]
14pub struct ClearArgs {
15 #[arg(long)]
17 pub older_than: Option<u64>,
18}
19
20pub async fn execute(cmd: CacheCommand) -> Result<()> {
21 match cmd {
22 CacheCommand::Clear(args) => clear(args).await,
23 CacheCommand::Stats => stats().await,
24 }
25}
26
27async fn clear(args: ClearArgs) -> Result<()> {
28 let cache = Cache::new()?;
29 let stats = cache.clear(args.older_than)?;
30
31 println!("{}", serde_json::to_string_pretty(&stats)?);
32
33 Ok(())
34}
35
36async fn stats() -> Result<()> {
37 let cache = Cache::new()?;
38 let stats = cache.stats()?;
39
40 println!("{}", serde_json::to_string_pretty(&stats)?);
41
42 Ok(())
43}