From 2bcccb18a6cb8bf836f57c3d86f759b19699def2 Mon Sep 17 00:00:00 2001 From: metamuffin Date: Sat, 24 Jan 2026 23:06:33 +0100 Subject: cache as object --- transcoder/src/image.rs | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) (limited to 'transcoder/src/image.rs') diff --git a/transcoder/src/image.rs b/transcoder/src/image.rs index 14b3e53..eaf8b86 100644 --- a/transcoder/src/image.rs +++ b/transcoder/src/image.rs @@ -3,21 +3,29 @@ which is licensed under the GNU Affero General Public License (version 3); see /COPYING. Copyright (C) 2026 metamuffin */ -use anyhow::{anyhow, Context, Result}; +use anyhow::{Context, Result, anyhow}; use image::imageops::FilterType; -use jellycache::{cache, cache_read, HashKey}; +use jellycache::{Cache, HashKey}; use log::{debug, info}; use rgb::FromSlice; use std::io::Cursor; -pub fn transcode(key: &str, quality: u32, speed: u8, width: usize) -> Result> { - cache( +pub fn transcode( + cache: &Cache, + key: &str, + quality: u32, + speed: u8, + width: usize, +) -> Result> { + cache.cache( &format!( "transcode/image/{}-W{width}-Q{quality}-S{speed}", HashKey(key) ), move || { - let input = cache_read(key)?.ok_or(anyhow!("transcode cache key missing"))?; + let input = cache + .read(key)? + .ok_or(anyhow!("transcode cache key missing"))?; info!("encoding image (speed={speed}, quality={quality}, width={width})"); // TODO: use better image library that supports AVIF -- cgit v1.3