rive-cache-inmemory 1.0.0

In-memory cache for Rive.
Documentation
  • Coverage
  • 100%
    28 out of 28 items documented5 out of 17 items with examples
  • Size
  • Source code size: 53.24 kB This is the summed size of all the files inside the crates.io package for this release.
  • Documentation size: 5.62 MB This is the summed size of all files generated by rustdoc for all configured targets
  • Links
  • Repository
  • crates.io
  • Dependencies
  • Versions
  • Owners
  • arslee07

rive-cache-inmemory

rive-cache-inmemory is an implementation of an in-memory cache for the Rive ecosystem. It's intended to be used only within the current process.

It processes incoming events, and adds/modifies/removes resources depending on the event type and data.

There's also a simple API for iterating over resource entities and getting cache statistics (such as the number of stored users).

Example

Update a cache with incoming events from the gateway:

use futures::StreamExt;
use std::{env, error::Error};

use rive_cache_inmemory::InMemoryCache;
use rive_gateway::Gateway;
use rive_models::authentication::Authentication;

#[tokio::main]
async fn main() -> Result<(), Box<dyn Error>> {
    let auth = Authentication::SessionToken(env::var("TOKEN")?);

    let mut gateway = Gateway::connect(auth).await?;

    // Create a cache with messages and emojis caching disabled:
    let cache = InMemoryCache::builder()
        .cache_messages(false)
        .cache_emojis(false)
        .build();

    while let Some(event) = gateway.next().await {
        let event = event?;

        // Update the cache with the event:
        cache.update(&event);
    }

    Ok(())
}