Quick Start Guide

Description:

Step-by-step walkthrough for the most common usage scenarios.

Main Content:

Here’s how you can quickly integrate caching utilities into your contract:

use smartcache_sdk::{is_contract_cacheable, AutoCacheOptIn, emit_cache_opt_in};
use stylus_sdk::prelude::*;
use alloy_primitives::Address;

#[public]
impl MyContract {
    pub fn is_cacheable(&self) -> bool {
        is_contract_cacheable()
    }

    pub fn opt_into_cache(&self, contract_addr: Address) {
        emit_cache_opt_in(contract_addr);
    }
}
  • is_contract_cacheable() → returns whether the contract qualifies for cache.

  • emit_cache_opt_in() → emits the AutoCacheOptIn event, signaling the SmartCache system to register your contract.

This minimal example gives your contract caching capabilities instantly. For developers who prefer a trait-based approach, SmartCache provides the Cacheable trait.

Once implemented, you can simply call:

This makes your contract cleaner, modular, and compliant with SmartCache best practices.

Last updated