multiversx-cache-patterns
MultiversX Cache Patterns
Why Cache?
- Storage reads/writes are the most expensive operations in MultiversX smart contracts
- A single endpoint that reads 5 storage values and writes 3 back costs 8 storage operations
- With a cache: 5 reads on entry + 3 writes on exit = same, BUT intermediate reads within the function are FREE (in-memory)
Pattern 1: Write-Back Cache with Drop Trait
The core pattern: load state into a struct on entry, mutate in memory, commit on scope exit via Drop.
multiversx_sc::imports!();
use multiversx_sc::derive_imports::*;
pub struct StorageCache<'a, C>
where
C: crate::storage::StorageModule,
{
More from multiversx/mx-ai-skills
multiversx-clarification-expert
Identify ambiguous requirements and ask targeted clarifying questions for MultiversX development. Use when user requests are vague, missing technical constraints, or have conflicting requirements.
20multiversx-protocol-experts
Deep protocol knowledge for MultiversX architecture including sharding, consensus, ESDT standards, and cross-shard transactions. Use when reviewing protocol-level code, designing complex dApp architectures, or troubleshooting cross-shard issues.
20multiversx-spec-compliance
Verify smart contract implementations match their specifications, whitepapers, and MIP standards. Use when auditing for specification adherence, validating tokenomics implementations, or checking MIP compliance.
20multiversx-smart-contracts
Build MultiversX smart contracts with Rust. Use when app needs blockchain logic, token creation, NFT minting, staking, crowdfunding, or any on-chain functionality requiring custom smart contracts.
19multiversx-constant-time
Verify cryptographic operations execute in constant time to prevent timing attacks. Use when auditing custom crypto implementations, secret comparisons, or security-sensitive algorithms in smart contracts.
19multiversx-wasm-debug
Analyze compiled WASM binaries for size optimization, panic analysis, and debugging with DWARF symbols. Use when troubleshooting contract deployment issues, optimizing binary size, or debugging runtime errors.
19