From: Lukas Wagner <l.wagner@proxmox.com>
To: pdm-devel@lists.proxmox.com
Subject: [PATCH datacenter-manager 2/4] add pdm_cache cache as a specialized wrapper around the namespaced cache
Date: Fri, 8 May 2026 17:03:28 +0200 [thread overview]
Message-ID: <20260508150330.363622-3-l.wagner@proxmox.com> (raw)
In-Reply-To: <20260508150330.363622-1-l.wagner@proxmox.com>
This is a thin wrapper around the previously introduced namespaced
key-value cache, but introducing PDM-specific concepts.
Instead of the higher-level read/write methods for locking a namespace,
this wrapper provides {read,write}_remote and {read,write}_global, for
accessing remote-specific and globally cached values. The
cache-namespaces are 'global' and 'remote-<remote-name>'.
The base directory for the cache is /var/cache/proxmox-datacenter-manager/cache
Signed-off-by: Lukas Wagner <l.wagner@proxmox.com>
---
Notes:
Not sure about the base directory /var/cache/proxmox-datacenter-manager/cache
Maybe 'api-cache' could be a nicer fit, since realistically, we probably
only ever cache API responses and aggregations thereof?
.../bin/proxmox-datacenter-privileged-api.rs | 7 ++
server/src/lib.rs | 1 +
server/src/pdm_cache.rs | 69 +++++++++++++++++++
3 files changed, 77 insertions(+)
create mode 100644 server/src/pdm_cache.rs
diff --git a/server/src/bin/proxmox-datacenter-privileged-api.rs b/server/src/bin/proxmox-datacenter-privileged-api.rs
index 6b490f2b..6e8ba611 100644
--- a/server/src/bin/proxmox-datacenter-privileged-api.rs
+++ b/server/src/bin/proxmox-datacenter-privileged-api.rs
@@ -102,6 +102,13 @@ fn create_directories() -> Result<(), Error> {
0o755,
)?;
+ pdm_config::setup::mkdir_perms(
+ concat!(pdm_buildcfg::PDM_CACHE_DIR_M!(), "/cache"),
+ api_user.uid,
+ api_user.gid,
+ 0o755,
+ )?;
+
server::jobstate::create_jobstate_dir()?;
Ok(())
diff --git a/server/src/lib.rs b/server/src/lib.rs
index 0b7642ab..5e8c0b64 100644
--- a/server/src/lib.rs
+++ b/server/src/lib.rs
@@ -9,6 +9,7 @@ pub mod jobstate;
pub mod metric_collection;
pub mod namespaced_cache;
pub mod parallel_fetcher;
+pub mod pdm_cache;
pub mod remote_cache;
pub mod remote_tasks;
pub mod remote_updates;
diff --git a/server/src/pdm_cache.rs b/server/src/pdm_cache.rs
new file mode 100644
index 00000000..a7370632
--- /dev/null
+++ b/server/src/pdm_cache.rs
@@ -0,0 +1,69 @@
+use std::{
+ path::{Path, PathBuf},
+ sync::LazyLock,
+ time::Duration,
+};
+
+use nix::sys::stat::Mode;
+use proxmox_sys::fs::CreateOptions;
+
+use crate::namespaced_cache::{
+ CacheError, NamespacedCache, ReadableCacheNamespace, WritableCacheNamespace,
+};
+
+static CACHE_INSTANCE: LazyLock<PdmCache> = LazyLock::new(|| {
+ let file_options = proxmox_product_config::default_create_options();
+ let dir_options = file_options.perm(Mode::from_bits_truncate(0o750));
+
+ PdmCache::new(
+ // FIXME: `/cache` seems slightly redundant, come up with something else...
+ PathBuf::from(concat!(pdm_buildcfg::PDM_CACHE_DIR_M!(), "/cache")),
+ dir_options,
+ file_options,
+ )
+});
+
+/// Return a handle to the global [`PdmCache`] instance.
+pub fn instance() -> &'static PdmCache {
+ &CACHE_INSTANCE
+}
+
+/// Cache for storing the results of API requests, as well as aggregations thereof.
+pub struct PdmCache(NamespacedCache);
+
+impl PdmCache {
+ /// Create a new cache instance.
+ ///
+ /// # Note
+ /// Most likely, you want to access the single global instance via [`pdm_cache::instance()`]
+ /// instead of calling `new` yourself.
+ fn new<P: AsRef<Path>>(
+ base_path: P,
+ dir_options: CreateOptions,
+ file_options: CreateOptions,
+ ) -> Self {
+ Self(NamespacedCache::new(base_path, dir_options, file_options))
+ }
+
+ /// Lock the cache for reading remote-specific data.
+ pub fn read_remote(&self, remote: &str) -> Result<ReadableCacheNamespace, CacheError> {
+ let namespace = format!("remote-{remote}");
+ self.0.read(&namespace, Duration::from_secs(10))
+ }
+
+ /// Lock the cache for writing remote-specific data.
+ pub fn write_remote(&self, remote: &str) -> Result<WritableCacheNamespace, CacheError> {
+ let namespace = format!("remote-{remote}");
+ self.0.write(&namespace, Duration::from_secs(10))
+ }
+
+ /// Lock the cache for reading global data.
+ pub fn read_global(&self) -> Result<ReadableCacheNamespace, CacheError> {
+ self.0.read("global", Duration::from_secs(10))
+ }
+
+ /// Lock the cache for writing global data.
+ pub fn write_global(&self) -> Result<WritableCacheNamespace, CacheError> {
+ self.0.write("global", Duration::from_secs(10))
+ }
+}
--
2.47.3
next prev parent reply other threads:[~2026-05-08 15:04 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-05-08 15:03 [RFC datacenter-manager 0/4] add generic, per-remote (and global) cache for remote API responses Lukas Wagner
2026-05-08 15:03 ` [PATCH datacenter-manager 1/4] add persistent, generic, namespaced key-value cache implementation Lukas Wagner
2026-05-08 15:03 ` Lukas Wagner [this message]
2026-05-08 15:03 ` [PATCH datacenter-manager 3/4] api: resources: subscriptions: switch over to pdm_cache Lukas Wagner
2026-05-08 15:03 ` [PATCH datacenter-manager 4/4] remote-updates: " Lukas Wagner
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20260508150330.363622-3-l.wagner@proxmox.com \
--to=l.wagner@proxmox.com \
--cc=pdm-devel@lists.proxmox.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.