Webhash Documentation
  • About WebHash
    • What is Webhash Protocol?
    • Digital Decay & Illusion of Decentralization
    • 3 Layer Solution
  • The three layers
    • Hosting Layer
      • Replication Algorithm
      • Technical Specification & Node Setup
      • Incentives and Penalty Mechanism
      • On Chain Content Registry
    • Gateway Layer
      • Content Retrival
      • Integrated Caching
      • Technical Specification
    • Application Layer
      • Developer-focused (like Vercel)
      • No-Code community (like Webflow)
      • AI Agent for complete beginners (prompt-to-website)
      • Web2 → WebHash
    • Website Permanance
      • Storage Pool
      • Inflationary Token Issuance
      • Self-Replication
      • Reputation
      • Community Archival Efforts
  • WebHash Token - $HASH
    • WebHash Token - $HASH
  • Eco-System Products
    • Modly AI
    • Hash Dweb Gateway: Chrome Extension
    • Eth.cd
    • Write.link
    • Widecanvas AI
    • Hash.is
    • eth.lk – Ethereum Gateway
    • arb.qa – Arbitrum Gateway
    • bnb.qa – Binance Smart Chain Gateway
    • HashVault
  • Token Trails
  • Governance
    • WebHash DAO
    • Governance Structure
    • Key Functions of the DAO
    • Content Moderation & Protection
    • Governance Process & Voting
    • The Future of WebHash DAO
Powered by GitBook
On this page
  1. The three layers
  2. Gateway Layer

Integrated Caching

Varnish as the First Layer

  • Varnish runs in front of the content retriever (which fetches content from the Hosting Layer).

  • It checks if the requested CID is already cached before forwarding the request.

Cache Storage in Varnish

Varnish stores:

  1. Static files (HTML, CSS, JS, images, videos)

  2. Pre-fetched content for fast loading

  3. Frequently accessed website CIDs

Step-by-Step Caching Process:

A. User Requests Content (example.com)

  1. The request reaches Varnish (gateway1.com).

  2. Varnish checks its cache memory for the CID.

B. Cache Hit (Content Found in Varnish)

  1. If the content exists in cache, it is immediately served from RAM.

  2. Response time: <1ms (instant page load).

C. Cache Miss (Content Not in Varnish)

  1. Varnish forwards the request to the Webhash Gateway Backend.

  2. The Gateway Backend queries the Hosting Layer for the CID.

  3. If content is found, it is stored in Varnish and then served to the user.

Varnish Cache Configuration for Webhash

The Varnish Configuration Language (VCL) is used to control caching behavior.

vcl 4.1;

backend hosting_layer {
    .host = "localhost";
    .port = "5050"; # Webhash Gateway Backend Port
    .first_byte_timeout = 60s; # Wait for hosting layer to respond
    .connect_timeout = 5s;
    .between_bytes_timeout = 30s;
}

sub vcl_recv {
    # Extract CID from the request URL
    if (req.url ~ "^/ipfs/") {
        set req.backend_hint = hosting_layer;
    }

    # Set caching policy
    set req.http.Cache-Control = "max-age=3600"; # Cache for 1 hour
}

sub vcl_backend_response {
    # Cache only successful responses
    if (beresp.status == 200) {
        set beresp.ttl = 1h; # Keep in cache for 1 hour
    } else {
        set beresp.ttl = 0s; # Do not cache errors
    }
}

sub vcl_deliver {
    # Add debug header to indicate cache status
    if (obj.hits > 0) {
        set resp.http.X-Cache = "HIT";
    } else {
        set resp.http.X-Cache = "MISS";
    }
}

Explanation of Varnish Cache Rules

  1. Caches content for 1 hour to improve performance.

  2. Requests are forwarded to Hosting Layer only if necessary.

  3. Responses are tagged with X-Cache (HIT/MISS) for debugging.

Cache Purging for New Website Updates

When a new CID is published, gateways can invalidate the cache for a specific website.

varnishadm "ban req.url ~ /ipfs/QmOldCID"
PreviousContent RetrivalNextTechnical Specification

Last updated 1 month ago