stylus-cache-sdk

Crates.iostylus-cache-sdk
lib.rsstylus-cache-sdk
version0.1.0
created_at2025-07-29 05:32:17.4985+00
updated_at2025-07-29 05:32:17.4985+00
descriptionA Rust SDK for Stylus contract caching utilities with AutoCacheOptIn event support
homepagehttps://github.com/meetpaladiya44/Smart_Cache_AutoCache_RUST_setup/tree/master
repositoryhttps://github.com/meetpaladiya44/Smart_Cache_AutoCache_RUST_setup/tree/master
max_upload_size
id1771954
size54,404
Meet Paladiya (meetpaladiya44)

documentation

https://docs.rs/stylus-cache-sdk

README

Stylus Cache SDK

A Rust SDK for Stylus contract caching utilities with AutoCacheOptIn event support.

Features

  • 🚀 Easy Integration: Simple functions for contract caching
  • 📝 Event Support: Built-in AutoCacheOptIn event
  • 🛠️ Trait-based: Optional Cacheable trait for standardized implementation
  • 📚 Well Documented: Comprehensive documentation and examples

Installation

Add this to your Cargo.toml:

[dependencies]
stylus-cache-sdk = "0.1.0"

Quick Start

Basic Usage

use stylus_cache_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);
    }
}

Using the Cacheable Trait

use stylus_cache_sdk::Cacheable;
use stylus_sdk::prelude::*;
use alloy_primitives::Address;

#[public]
impl MyContract {
    // Contract implementation
}

impl Cacheable for MyContract {}

// Now you can use:
// contract.is_cacheable() -> bool
// contract.opt_into_cache(address) -> emits AutoCacheOptIn event

Updated Counter Contract Example

#![cfg_attr(not(any(test, feature = "export-abi")), no_main)]
#![cfg_attr(not(any(test, feature = "export-abi")), no_std)]

#[macro_use]
extern crate alloc;

use stylus_sdk::{alloy_primitives::U256, prelude::*};
use stylus_cache_sdk::{is_contract_cacheable, Cacheable};

sol_storage! {
    #[entrypoint]
    pub struct Counter {
        uint256 number;
    }
}

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

    pub fn numbers(&self) -> U256 {
        self.number.get()
    }

    // ... rest of your contract methods
}

impl Cacheable for Counter {}

API Reference

Functions

  • is_contract_cacheable() -> bool: Returns whether the contract is cacheable
  • emit_cache_opt_in(contract_addr: Address): Emits the AutoCacheOptIn event

Events

  • AutoCacheOptIn(address indexed contract_addr): Event for cache opt-in

Traits

  • Cacheable: Trait providing default caching functionality

Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

License

This project is licensed under either of

at your option.

Commit count: 0

cargo fmt