pub struct HashMapActor { /* private fields */ }Expand description
An implementation of ExpiryStore based on async
actix actors and HashMap
It relies on tokio’s DelayQueue internally to manage expiration, and it doesn’t have any lock as it runs in single threaded async arbiter.
§Example
use actix_storage::Storage;
use actix_storage_hashmap::HashMapActor;
use actix_web::{App, HttpServer};
#[actix_web::main]
async fn main() -> std::io::Result<()> {
let store = HashMapActor::start_default();
// OR
let store = HashMapActor::with_capacity(100).start();
let storage = Storage::build().expiry_store(store).finish();
let server = HttpServer::new(move || {
App::new()
.data(storage.clone())
});
server.bind("localhost:5000")?.run().await
}requires [“actor”] feature
Implementations§
Source§impl HashMapActor
impl HashMapActor
Sourcepub fn with_capacity(capacity: usize) -> Self
pub fn with_capacity(capacity: usize) -> Self
Makes a new HashMapActor with specified HashMap capacity without starting it
Sourcepub fn with_channel_size(input_buffer: usize, output_buffer: usize) -> Self
pub fn with_channel_size(input_buffer: usize, output_buffer: usize) -> Self
Makes a new HashMapActor with specified channel capacity without starting it
Buffer sizes are used for internal expiry channel provider, input is for the channel providing commands expire/extend/expiry/persist and output is the other channel that sends back expired items.
Sourcepub fn with_capacity_and_channel_size(
capacity: usize,
input_buffer: usize,
output_buffer: usize,
) -> Self
pub fn with_capacity_and_channel_size( capacity: usize, input_buffer: usize, output_buffer: usize, ) -> Self
Makes a new HashMapActor with specified HashMap and channel capacity without starting it
Buffer sizes are used for internal expiry channel provider, input is for the channel providing commands expire/extend/expiry/persist and output is the other channel that sends back expired items.
Sourcepub fn start(self) -> Addr<Self>
pub fn start(self) -> Addr<Self>
Equivalent of actix::Actor::start for when actix::Actor is not in scope
Sourcepub fn start_default() -> Addr<Self>
pub fn start_default() -> Addr<Self>
Equivalent of actix::Actor::start_default for when actix::Actor is not in scope
Trait Implementations§
Source§impl Actor for HashMapActor
impl Actor for HashMapActor
Source§type Context = Context<HashMapActor>
type Context = Context<HashMapActor>
Source§fn started(&mut self, ctx: &mut Self::Context)
fn started(&mut self, ctx: &mut Self::Context)
Source§fn stopping(&mut self, ctx: &mut Self::Context) -> Running
fn stopping(&mut self, ctx: &mut Self::Context) -> Running
Actor::Stopping state. Read more