pub struct StateStore {
pub base_path: PathBuf,
}Expand description
A filesystem-based persistent state store.
Files are organized as <base_path>/<category>/<name>.md or
<base_path>/<category>/<name>.json.
Fields§
§base_path: PathBufRoot directory for all state files.
Implementations§
Source§impl StateStore
impl StateStore
Sourcepub fn new(base_path: PathBuf) -> Result<Self>
pub fn new(base_path: PathBuf) -> Result<Self>
Creates a new state store, initializing the directory if needed.
§Example
use oxios_kernel::state_store::StateStore;
use std::path::PathBuf;
let store = StateStore::new(PathBuf::from("/tmp/oxios-state")).unwrap();Sourcepub async fn save_markdown(
&self,
category: &str,
name: &str,
content: &str,
) -> Result<()>
pub async fn save_markdown( &self, category: &str, name: &str, content: &str, ) -> Result<()>
Save a markdown file under the given category.
Sourcepub async fn load_markdown(
&self,
category: &str,
name: &str,
) -> Result<Option<String>>
pub async fn load_markdown( &self, category: &str, name: &str, ) -> Result<Option<String>>
Load a markdown file from the given category.
Sourcepub async fn list_category(&self, category: &str) -> Result<Vec<String>>
pub async fn list_category(&self, category: &str) -> Result<Vec<String>>
List all markdown files in a category (names without extension).
Sourcepub async fn save_json<T: Serialize>(
&self,
category: &str,
name: &str,
data: &T,
) -> Result<()>
pub async fn save_json<T: Serialize>( &self, category: &str, name: &str, data: &T, ) -> Result<()>
Save a serializable value as JSON under the given category.
Source§impl StateStore
impl StateStore
Sourcepub async fn save_session(&self, session: &Session) -> Result<()>
pub async fn save_session(&self, session: &Session) -> Result<()>
Saves a session to the sessions category.
Sourcepub async fn save_session_with_prune(
&self,
session: &Session,
prune_config: &PruneConfig,
) -> Result<()>
pub async fn save_session_with_prune( &self, session: &Session, prune_config: &PruneConfig, ) -> Result<()>
Saves a session and then runs pruning if auto_prune is enabled.
Sourcepub async fn load_session(
&self,
session_id: &SessionId,
) -> Result<Option<Session>>
pub async fn load_session( &self, session_id: &SessionId, ) -> Result<Option<Session>>
Loads a session by ID.
Sourcepub async fn list_sessions(&self) -> Result<Vec<SessionSummary>>
pub async fn list_sessions(&self) -> Result<Vec<SessionSummary>>
Lists all sessions (sorted by updated_at descending).
Sourcepub async fn delete_session(&self, session_id: &SessionId) -> Result<bool>
pub async fn delete_session(&self, session_id: &SessionId) -> Result<bool>
Deletes a session by ID.
Sourcepub async fn get_or_create_session(
&self,
user_id: &str,
session_id: Option<&SessionId>,
) -> Result<Session>
pub async fn get_or_create_session( &self, user_id: &str, session_id: Option<&SessionId>, ) -> Result<Session>
Gets or creates a session for a user, initializing with the given session ID.
Sourcepub async fn update_session(&self, session: &Session) -> Result<()>
pub async fn update_session(&self, session: &Session) -> Result<()>
Updates an existing session, saving it to disk.
Sourcepub async fn prune_sessions(&self, config: &PruneConfig) -> Result<usize>
pub async fn prune_sessions(&self, config: &PruneConfig) -> Result<usize>
Prune sessions based on configuration.
Removes sessions that exceed TTL or exceed the maximum count. Returns the number of sessions pruned.
Trait Implementations§
Source§impl AuditPersistence for StateStore
impl AuditPersistence for StateStore
Source§impl Clone for StateStore
impl Clone for StateStore
Source§fn clone(&self) -> StateStore
fn clone(&self) -> StateStore
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more