pub struct CachePlugin { /* private fields */ }Expand description
The cache engine – a Redis-like in-memory data structure store.
Implementations§
Source§impl CachePlugin
impl CachePlugin
pub fn new(max_keys: usize) -> Self
Sourcepub fn incr(&self, key: &str) -> Result<i64, String>
pub fn incr(&self, key: &str) -> Result<i64, String>
INCR key – increment integer value, creates if not exists (starts at 0).
Sourcepub fn setnx(&self, key: &str, value: &str, ttl: Option<u64>) -> bool
pub fn setnx(&self, key: &str, value: &str, ttl: Option<u64>) -> bool
SETNX – set only if key doesn’t exist. Returns true if set.
Sourcepub fn getset(&self, key: &str, value: &str) -> Option<String>
pub fn getset(&self, key: &str, value: &str) -> Option<String>
GETSET – set new value and return old value.
Sourcepub fn ttl(&self, key: &str) -> i64
pub fn ttl(&self, key: &str) -> i64
TTL key – returns remaining seconds, -1 if no expiry, -2 if key doesn’t exist.
Sourcepub fn expire(&self, key: &str, seconds: u64) -> bool
pub fn expire(&self, key: &str, seconds: u64) -> bool
EXPIRE key seconds – set expiry on existing key.
Sourcepub fn keys(&self, pattern: &str) -> Vec<String>
pub fn keys(&self, pattern: &str) -> Vec<String>
KEYS pattern – find keys matching glob pattern.
Sourcepub fn lpush(&self, key: &str, value: &str) -> usize
pub fn lpush(&self, key: &str, value: &str) -> usize
LPUSH key value – push to front, creates list if needed.
Sourcepub fn lrange(&self, key: &str, start: i64, stop: i64) -> Vec<String>
pub fn lrange(&self, key: &str, start: i64, stop: i64) -> Vec<String>
LRANGE key start stop – get range (inclusive, supports negative indices).
Sourcepub fn sadd(&self, key: &str, member: &str) -> bool
pub fn sadd(&self, key: &str, member: &str) -> bool
SADD key member – add to set. Returns true if the member was newly added.
Sourcepub fn sinter(&self, key1: &str, key2: &str) -> Vec<String>
pub fn sinter(&self, key1: &str, key2: &str) -> Vec<String>
SINTER key1 key2 – intersection of two sets.
Sourcepub fn sunion(&self, key1: &str, key2: &str) -> Vec<String>
pub fn sunion(&self, key1: &str, key2: &str) -> Vec<String>
SUNION key1 key2 – union of two sets.
Sourcepub fn hgetall(&self, key: &str) -> HashMap<String, String>
pub fn hgetall(&self, key: &str) -> HashMap<String, String>
HGETALL key – all field-value pairs.
Sourcepub fn hincrby(
&self,
key: &str,
field: &str,
amount: i64,
) -> Result<i64, String>
pub fn hincrby( &self, key: &str, field: &str, amount: i64, ) -> Result<i64, String>
HINCRBY key field amount
Sourcepub fn zrank(&self, key: &str, member: &str) -> Option<usize>
pub fn zrank(&self, key: &str, member: &str) -> Option<usize>
ZRANK key member – rank by score (0-based).
Sourcepub fn zrange(&self, key: &str, start: usize, stop: usize) -> Vec<(String, f64)>
pub fn zrange(&self, key: &str, start: usize, stop: usize) -> Vec<(String, f64)>
ZRANGE key start stop – members by rank range (inclusive).
Sourcepub fn info(&self) -> CacheStats
pub fn info(&self) -> CacheStats
INFO – cache statistics.
Sourcepub fn key_type(&self, key: &str) -> Option<&'static str>
pub fn key_type(&self, key: &str) -> Option<&'static str>
TYPE key – returns the type of value stored.
Sourcepub fn cleanup_expired(&self) -> usize
pub fn cleanup_expired(&self) -> usize
Cleanup expired keys (call periodically). Returns number of keys removed.
Trait Implementations§
Source§impl Plugin for CachePlugin
impl Plugin for CachePlugin
Source§fn on_init(&self, _ctx: &PluginContext)
fn on_init(&self, _ctx: &PluginContext)
Source§fn routes(&self) -> Vec<PluginRoute>
fn routes(&self) -> Vec<PluginRoute>
Source§fn before_insert(
&self,
_entity: &str,
_data: &mut Value,
_auth: &AuthContext,
) -> Result<(), PluginError>
fn before_insert( &self, _entity: &str, _data: &mut Value, _auth: &AuthContext, ) -> Result<(), PluginError>
Source§fn after_insert(
&self,
_entity: &str,
_id: &str,
_data: &Value,
_auth: &AuthContext,
)
fn after_insert( &self, _entity: &str, _id: &str, _data: &Value, _auth: &AuthContext, )
Source§fn before_update(
&self,
_entity: &str,
_id: &str,
_data: &mut Value,
_auth: &AuthContext,
) -> Result<(), PluginError>
fn before_update( &self, _entity: &str, _id: &str, _data: &mut Value, _auth: &AuthContext, ) -> Result<(), PluginError>
Source§fn after_update(
&self,
_entity: &str,
_id: &str,
_data: &Value,
_auth: &AuthContext,
)
fn after_update( &self, _entity: &str, _id: &str, _data: &Value, _auth: &AuthContext, )
Source§fn before_delete(
&self,
_entity: &str,
_id: &str,
_auth: &AuthContext,
) -> Result<(), PluginError>
fn before_delete( &self, _entity: &str, _id: &str, _auth: &AuthContext, ) -> Result<(), PluginError>
Source§fn after_delete(&self, _entity: &str, _id: &str, _auth: &AuthContext)
fn after_delete(&self, _entity: &str, _id: &str, _auth: &AuthContext)
Source§fn on_request(
&self,
_method: &str,
_path: &str,
_auth: &AuthContext,
) -> Result<(), PluginError>
fn on_request( &self, _method: &str, _path: &str, _auth: &AuthContext, ) -> Result<(), PluginError>
Source§fn on_request_with_meta(
&self,
method: &str,
path: &str,
auth: &AuthContext,
_meta: &RequestMeta<'_>,
) -> Result<(), PluginError>
fn on_request_with_meta( &self, method: &str, path: &str, auth: &AuthContext, _meta: &RequestMeta<'_>, ) -> Result<(), PluginError>
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.