| Crates.io | stylus-cache-sdk |
| lib.rs | stylus-cache-sdk |
| version | 0.1.0 |
| created_at | 2025-07-29 05:32:17.4985+00 |
| updated_at | 2025-07-29 05:32:17.4985+00 |
| description | A Rust SDK for Stylus contract caching utilities with AutoCacheOptIn event support |
| homepage | https://github.com/meetpaladiya44/Smart_Cache_AutoCache_RUST_setup/tree/master |
| repository | https://github.com/meetpaladiya44/Smart_Cache_AutoCache_RUST_setup/tree/master |
| max_upload_size | |
| id | 1771954 |
| size | 54,404 |
A Rust SDK for Stylus contract caching utilities with AutoCacheOptIn event support.
AutoCacheOptIn eventCacheable trait for standardized implementationAdd this to your Cargo.toml:
[dependencies]
stylus-cache-sdk = "0.1.0"
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);
}
}
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
#![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 {}
is_contract_cacheable() -> bool: Returns whether the contract is cacheableemit_cache_opt_in(contract_addr: Address): Emits the AutoCacheOptIn eventAutoCacheOptIn(address indexed contract_addr): Event for cache opt-inCacheable: Trait providing default caching functionalityContributions are welcome! Please feel free to submit a Pull Request.
This project is licensed under either of
at your option.