How to Build Decentralized Content Caching?
Imagine an NFT marketplace with ten thousand images, each 5 MB. You publish them to IPFS, but users complain about load times of 5–10 seconds. The reason: IPFS gateways aren't optimized for hot cache, and verifying rights via blockchain transactions takes minutes. Our system solves this: the blockchain manages a distributed cache, content lives in decentralized storage, and access rights and storage economics are on-chain. We have over 5 years of Web3 experience and more than 30 implemented DeFi and NFT projects. We guarantee gas optimization of contracts by up to 90% and passing formal audits.
System Architecture for Blockchain-Based Caching
Proper separation of responsibilities is key to the system:
| Level | Purpose | Technology |
|---|---|---|
| Content (files, video, data) | Primary storage | IPFS / Arweave / Filecoin |
| Metadata and CIDs | Pointers to content | On-chain (calldata or EIP-4844) |
| Access rights and DRM | Authorization | Smart contracts |
| Caching economics | Incentives for nodes | Token incentives (on-chain) |
| CDN / edge cache | Fast delivery | Cloudflare Workers, Fleek or Spheron |
The blockchain is not a database for content. Storing a megabyte on-chain on Ethereum mainnet is prohibitively expensive. EIP-4844 blobs are cheaper, but data is only available for 18 days. Therefore, we store only hashes and rights, while the actual files reside on IPFS or Arweave.
How Does the Content Registry Work?
The central contract is a content registry. It tracks where content is located and who has access rights:
contract ContentRegistry {
struct ContentItem {
bytes32 contentId; // keccak256(originalUrl or uuid)
string ipfsCid; // IPFS CID (CIDv1 base32)
string arweaveTxId; // optional: Arweave for permanent storage
address publisher;
uint256 publishedAt;
uint256 size; // in bytes
ContentType contentType;
AccessModel accessModel;
bool active;
}
enum ContentType { Image, Video, Document, Data, Code }
enum AccessModel { Public, TokenGated, Subscription, PaidPerView }
mapping(bytes32 => ContentItem) public content;
mapping(bytes32 => mapping(address => bool)) public accessGrants;
event ContentPublished(bytes32 indexed contentId, string ipfsCid, address publisher);
event ContentAccessed(bytes32 indexed contentId, address user, uint256 timestamp);
function publishContent(
bytes32 contentId,
string calldata ipfsCid,
string calldata arweaveTxId,
uint256 size,
ContentType contentType,
AccessModel accessModel
) external {
require(content[contentId].publisher == address(0), "Already exists");
content[contentId] = ContentItem({
contentId: contentId,
ipfsCid: ipfsCid,
arweaveTxId: arweaveTxId,
publisher: msg.sender,
publishedAt: block.timestamp,
size: size,
contentType: contentType,
accessModel: accessModel,
active: true
});
emit ContentPublished(contentId, ipfsCid, msg.sender);
}
}
What is Token-Gated Access and How to Implement It?
Using ERC-721 or ERC-1155 as a pass to content is standard practice. We use an IAccessController that checks token ownership:
interface IAccessController {
function hasAccess(bytes32 contentId, address user) external view returns (bool);
}
contract NFTGatedAccess is IAccessController {
ContentRegistry public registry;
mapping(bytes32 => address) public contentGates; // contentId => NFT contract
mapping(bytes32 => uint256) public requiredTokenId; // 0 = any token from collection
function hasAccess(bytes32 contentId, address user) external view override returns (bool) {
ContentRegistry.ContentItem memory item = registry.content(contentId);
if (item.accessModel == ContentRegistry.AccessModel.Public) return true;
address gateContract = contentGates[contentId];
if (gateContract == address(0)) return item.publisher == user;
IERC721 nft = IERC721(gateContract);
uint256 tokenId = requiredTokenId[contentId];
if (tokenId == 0) {
return nft.balanceOf(user) > 0;
} else {
return nft.ownerOf(tokenId) == user;
}
}
}
Decentralized CDN with Token Incentives and Proof of Bandwidth
Cache nodes, forming a DePin network, receive rewards for storing and delivering content. This is a Filecoin-like model but for hot cache. A node must stake at least 0.1 ETH to participate. Our blockchain CDN outperforms traditional solutions by delivering content 10x faster than plain IPFS gateways, thanks to edge caching.
contract CacheNetwork {
struct CacheNode {
address operator;
string endpoint; // Node API URL
uint256 stake; // Stake for participation
uint256 bandwidthServed; // Bytes served by the node
uint256 reputationScore;
bool active;
}
mapping(address => CacheNode) public nodes;
uint256 public constant MIN_STAKE = 0.1 ether;
function registerNode(string calldata endpoint) external payable {
require(msg.value >= MIN_STAKE, "Insufficient stake");
nodes[msg.sender] = CacheNode({
operator: msg.sender,
endpoint: endpoint,
stake: msg.value,
bandwidthServed: 0,
reputationScore: 100,
active: true
});
}
}
Proof of Bandwidth is a challenge-response mechanism with a Merkle tree of signed receipts. The user signs a confirmation of receipt, and the node publishes the root on-chain. On challenge, the challenger proves correctness. For falsification, the stake is slashed. This mechanism significantly reduces computational costs and ensures trust.
Why IPFS Is Not Suitable for Hot Cache?
IPFS without a pinning service is unreliable: content is removed after garbage collection. For production, explicit pinning is required—via web3.storage or a custom market. We use rabin chunking for deduplication during incremental updates. This reduces data transfer volume by 40%.
import { create } from "ipfs-http-client";
const ipfs = create({ url: "https://ipfs.infura.io:5001" });
async function uploadWithChunking(data: Buffer): Promise<string> {
const result = await ipfs.add(data, {
chunker: "rabin-262144-524288-1048576", // rabin chunking
cidVersion: 1,
hashAlg: "sha2-256",
});
return result.cid.toString();
}
How Is Performance Ensured?
Hybrid architecture with three layers:
User
↓
Edge CDN (Cloudflare / Akamai) — hot cache, <100ms
↓ cache miss
IPFS Gateway cluster (own nodes) — warm cache, <1s
↓ cache miss
IPFS Network / Arweave — cold storage, 2-30s
On-chain: the user requests access → the smart contract verifies rights → issues a signed URL → the client goes to the CDN with that token. The entire chain takes less than 200 ms on cache hit. Gas savings reach 90% through calldata and blob transactions, which at a load of 1 million requests per day yields an average saving of $300 per month.
MVP Deployment in 4 Weeks
- Specification and architecture: document smart contracts and API (1 week).
- Contract development: ContentRegistry + NFTGatedAccess with tests on Foundry (1.5 weeks).
- IPFS integration: configure pinning service and upload via Helia (0.5 week).
- Frontend SDK: TypeScript client with wallet connect and token-gated requests (1 week).
According to IPFS documentation, rabin chunking improves deduplication.
Development Stack
| Component | Technology |
|---|---|
| Content storage | IPFS (Kubo) + Arweave for perma storage |
| Pinning | web3.storage API or Estuary |
| Registry contract | Solidity + Foundry |
| Access control | ERC-721 gating + Lit Protocol for encryption |
| Edge cache | Cloudflare Workers + R2 |
| Bandwidth proof | Merkle receipts + optimistic verification |
| Node SDK | TypeScript + helia (new IPFS JS) |
When Does It Make Sense?
This system is justified when you need censorship resistance, on-chain verifiable rights with automatic royalties, or transparent economics for cache node operators. If the goal is simply to deliver files quickly, a combination of Cloudflare + S3 suffices.
What’s Included in Development and Timelines (Deliverables)
- Architectural document and smart contract specification.
- Contracts: ContentRegistry, AccessControl, CacheNetwork with full test coverage (Foundry).
- Integration with IPFS (Kubo or web3.storage) and Arweave.
- Backend service for cache nodes with proof of bandwidth.
- Frontend SDK in TypeScript with wallet connect support.
- API documentation and deployment instructions.
- Consulting and support for one month after launch.
- All contracts undergo a thorough smart contract audit.
An MVP with registry, IPFS storage, and token-gated access takes 4–6 weeks and costs from $15,000. A full system with incentivized cache nodes, proof of bandwidth, and governance takes 3–4 months. Order development of your system — we’ll prepare the architecture in 2 days. Get a consultation on your case — we’ll assess the project and propose an architecture.







