Skip to main content

CachePlugin

Struct CachePlugin 

Source
pub struct CachePlugin { /* private fields */ }
Expand description

The cache engine – a Redis-like in-memory data structure store.

Implementations§

Source§

impl CachePlugin

Source

pub fn new(max_keys: usize) -> Self

Source

pub fn set(&self, key: &str, value: &str, ttl: Option<u64>)

SET key value [EX seconds]

Source

pub fn get(&self, key: &str) -> Option<String>

GET key – returns None if expired or missing.

Source

pub fn del(&self, key: &str) -> bool

DEL key – returns true if key existed.

Source

pub fn exists(&self, key: &str) -> bool

EXISTS key

Source

pub fn incr(&self, key: &str) -> Result<i64, String>

INCR key – increment integer value, creates if not exists (starts at 0).

Source

pub fn decr(&self, key: &str) -> Result<i64, String>

DECR key

Source

pub fn incrby(&self, key: &str, amount: i64) -> Result<i64, String>

INCRBY key amount

Source

pub fn setnx(&self, key: &str, value: &str, ttl: Option<u64>) -> bool

SETNX – set only if key doesn’t exist. Returns true if set.

Source

pub fn getset(&self, key: &str, value: &str) -> Option<String>

GETSET – set new value and return old value.

Source

pub fn mget(&self, keys: &[&str]) -> Vec<Option<String>>

MGET – get multiple keys.

Source

pub fn mset(&self, pairs: &[(&str, &str)])

MSET – set multiple keys.

Source

pub fn ttl(&self, key: &str) -> i64

TTL key – returns remaining seconds, -1 if no expiry, -2 if key doesn’t exist.

Source

pub fn expire(&self, key: &str, seconds: u64) -> bool

EXPIRE key seconds – set expiry on existing key.

Source

pub fn persist(&self, key: &str) -> bool

PERSIST key – remove expiry.

Source

pub fn keys(&self, pattern: &str) -> Vec<String>

KEYS pattern – find keys matching glob pattern.

Source

pub fn lpush(&self, key: &str, value: &str) -> usize

LPUSH key value – push to front, creates list if needed.

Source

pub fn rpush(&self, key: &str, value: &str) -> usize

RPUSH key value – push to back.

Source

pub fn lpop(&self, key: &str) -> Option<String>

LPOP key – pop from front.

Source

pub fn rpop(&self, key: &str) -> Option<String>

RPOP key – pop from back.

Source

pub fn lrange(&self, key: &str, start: i64, stop: i64) -> Vec<String>

LRANGE key start stop – get range (inclusive, supports negative indices).

Source

pub fn llen(&self, key: &str) -> usize

LLEN key – list length.

Source

pub fn sadd(&self, key: &str, member: &str) -> bool

SADD key member – add to set. Returns true if the member was newly added.

Source

pub fn srem(&self, key: &str, member: &str) -> bool

SREM key member – remove from set.

Source

pub fn smembers(&self, key: &str) -> Vec<String>

SMEMBERS key – all members.

Source

pub fn sismember(&self, key: &str, member: &str) -> bool

SISMEMBER key member

Source

pub fn scard(&self, key: &str) -> usize

SCARD key – set size.

Source

pub fn sinter(&self, key1: &str, key2: &str) -> Vec<String>

SINTER key1 key2 – intersection of two sets.

Source

pub fn sunion(&self, key1: &str, key2: &str) -> Vec<String>

SUNION key1 key2 – union of two sets.

Source

pub fn hset(&self, key: &str, field: &str, value: &str)

HSET key field value

Source

pub fn hget(&self, key: &str, field: &str) -> Option<String>

HGET key field

Source

pub fn hdel(&self, key: &str, field: &str) -> bool

HDEL key field

Source

pub fn hgetall(&self, key: &str) -> HashMap<String, String>

HGETALL key – all field-value pairs.

Source

pub fn hexists(&self, key: &str, field: &str) -> bool

HEXISTS key field

Source

pub fn hlen(&self, key: &str) -> usize

HLEN key

Source

pub fn hkeys(&self, key: &str) -> Vec<String>

HKEYS key – all field names.

Source

pub fn hincrby( &self, key: &str, field: &str, amount: i64, ) -> Result<i64, String>

HINCRBY key field amount

Source

pub fn zadd(&self, key: &str, score: f64, member: &str)

ZADD key score member

Source

pub fn zrem(&self, key: &str, member: &str) -> bool

ZREM key member

Source

pub fn zscore(&self, key: &str, member: &str) -> Option<f64>

ZSCORE key member

Source

pub fn zrank(&self, key: &str, member: &str) -> Option<usize>

ZRANK key member – rank by score (0-based).

Source

pub fn zrange(&self, key: &str, start: usize, stop: usize) -> Vec<(String, f64)>

ZRANGE key start stop – members by rank range (inclusive).

Source

pub fn zcard(&self, key: &str) -> usize

ZCARD key – sorted set size.

Source

pub fn dbsize(&self) -> usize

DBSIZE – total key count (excluding expired).

Source

pub fn flushall(&self)

FLUSHALL – delete everything.

Source

pub fn info(&self) -> CacheStats

INFO – cache statistics.

Source

pub fn key_type(&self, key: &str) -> Option<&'static str>

TYPE key – returns the type of value stored.

Source

pub fn cleanup_expired(&self) -> usize

Cleanup expired keys (call periodically). Returns number of keys removed.

Trait Implementations§

Source§

impl Plugin for CachePlugin

Source§

fn name(&self) -> &str

Unique name for this plugin.
Source§

fn on_init(&self, _ctx: &PluginContext)

Called once when the plugin is registered.
Source§

fn routes(&self) -> Vec<PluginRoute>

Custom API routes this plugin handles.
Source§

fn before_insert( &self, _entity: &str, _data: &mut Value, _auth: &AuthContext, ) -> Result<(), PluginError>

Called before an entity insert. Return Err to reject.
Source§

fn after_insert( &self, _entity: &str, _id: &str, _data: &Value, _auth: &AuthContext, )

Called after a successful insert.
Source§

fn before_update( &self, _entity: &str, _id: &str, _data: &mut Value, _auth: &AuthContext, ) -> Result<(), PluginError>

Called before an entity update. Return Err to reject.
Source§

fn after_update( &self, _entity: &str, _id: &str, _data: &Value, _auth: &AuthContext, )

Called after a successful update.
Source§

fn before_delete( &self, _entity: &str, _id: &str, _auth: &AuthContext, ) -> Result<(), PluginError>

Called before an entity delete. Return Err to reject.
Source§

fn after_delete(&self, _entity: &str, _id: &str, _auth: &AuthContext)

Called after a successful delete.
Source§

fn on_request( &self, _method: &str, _path: &str, _auth: &AuthContext, ) -> Result<(), PluginError>

Called on every incoming request (middleware).
Source§

fn on_request_with_meta( &self, method: &str, path: &str, auth: &AuthContext, _meta: &RequestMeta<'_>, ) -> Result<(), PluginError>

Richer variant of [on_request] that also receives per-request metadata (peer IP today; more fields may be added later). The default implementation delegates to on_request so existing plugins keep working without changes. Plugins that care about IP — notably rate limiting — override this hook.
Source§

fn on_session_create(&self, _user_id: &str, _token: &str)

Called when a new session is created.
Source§

fn entities(&self) -> Vec<ManifestEntity>

Additional manifest entities this plugin contributes.

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V