Logo

dev-resources.site

for different kinds of informations.

Setup IPFS images cache server in 5 min

Published at
5/19/2023
Categories
nft
ipfs
web3
python
Author
pvolnov
Categories
4 categories in total
nft
open
ipfs
open
web3
open
python
open
Author
7 person written this
pvolnov
open
Setup IPFS images cache server in 5 min

Introduction

In this tutorial, we will explore the importance of caching images from IPFS (InterPlanetary File System) and demonstrate how to set up a basic IPFS image caching service using the repository called ipfs-cache-server (https://github.com/pvolnov/ipfs-cache-server). Caching images from IPFS can greatly improve performance and reduce bandwidth usage, especially in scenarios where the same images are frequently accessed

Why we need to cache IPFS images?

IPFS is a distributed file system that allows storing and sharing content using cryptographic hashes. While IPFS provides a decentralized and resilient way to store and retrieve files, accessing files directly from IPFS can sometimes introduce performance challenges, especially when dealing with large files or high-demand scenarios. By caching IPFS images, we can alleviate some of these challenges by storing the frequently accessed images closer to the users, reducing the need for repeated network requests.

Lets go

1. Create a folder for image caching:

mkdir /var/www/cache
Enter fullscreen mode Exit fullscreen mode

2. Configure image share via nginx:

Install and configure Nginx to serve the cached images. Add the following Nginx configuration to the appropriate server block in your Nginx configuration file (e.g., /etc/nginx/sites-available/default or /etc/nginx/conf.d/default.conf):

location /ipfs/ {
    proxy_set_header X-Forwarded-For $remote_addr;
    proxy_set_header Host $http_host;
    proxy_pass http://127.0.0.1:7001;
}

location /cache/ {
    alias /var/www/cache/;
    expires 30d;
}

Enter fullscreen mode Exit fullscreen mode

In this configuration, requests to /ipfs/ will be proxied to the ipfs-cache-server running on 127.0.0.1:9090, while requests to /cache/ will serve the cached images directly from the /var/www/cache/ directory.

3. Setup cache server

git clone https://github.com/pvolnov/ipfs-cache-server
cd ipfs-cache-server
Enter fullscreen mode Exit fullscreen mode

Open the config.yml file and update the following configuration parameters:

  • folder_size: The maximum cache size in MB.
  • cache_folder: The path to the cache folder (default is ./cache).
  • image_server_prefix: web link to ngnix server to share images from cache folder
  • max_size: The maximum number of images in the cache folder. Set cache folder path in docker-compose.yml:

5. Add cache folder path

Open the docker-compose.yml file and update the volume mapping to your desired cache folder path:

volumes:
  - /var/www/here-storage/cache:/workdir/cache
Enter fullscreen mode Exit fullscreen mode

6. Run

docker-compose up
Enter fullscreen mode Exit fullscreen mode

How to use

Make all requests via cache server, create url https://<image server>/url?sz=XXX

Example

Result:
https://image.herewallet.app/nftstorage.link/ipfs/bafybeieboqph4qqf2n7lasq4ehn6snke2nhdqzde4i4hlywwd3dd7mcjma/U1307.png?sz=512

Conclusion:

Caching IPFS images can significantly enhance performance and reduce network overhead when serving frequently accessed images. In this tutorial, we explored the importance of image caching from IPFS and demonstrated how to set.

P.S. Add ⭐️ for https://github.com/pvolnov/ipfs-cache-server

ipfs Article's
30 articles in total
Favicon
How to work with CAR files with NestJS
Favicon
🎃🚀 Storacha Halloween Hackathon 2024: Time to Store Some Skeletons and Build Spooky Tech! 💻👻
Favicon
Ditch the Server, Own Your Words: Building a Decentralized Blog with IPFS
Favicon
Decentralized blog via ipfs
Favicon
How to Run Your Own IPFS Node and Share Files
Favicon
Hosting Websites on IPFS
Favicon
How to Deploy a Next JS App on IPFS (InterPlanetary File System) and automate using Fleek
Favicon
IPFS (InterPlanetary File System) Explained
Favicon
uploading file into pinata
Favicon
DRepo: A Decentralized Version Control System- Day 3
Favicon
Deploy Your HTML Website on IPFS with GitHub and Fleek
Favicon
O que é IPFS?
Favicon
Bakeree IPFS stands at the forefront of IPFS NFT Storage innovation.
Favicon
Simplifying IPFS with Spheron Network Effortless Web Hosting
Favicon
Top Tips for Successfully Hosting Your Static Site on IPFS
Favicon
Simplifying Comprehensive IPNS Management With Spheron Network
Favicon
Exploring Storage Options in Web3: Cloud, IPFS and On-Chain
Favicon
Navigating the IPFS Landscape: An Insider's Perspective
Favicon
Building a Decentralized Web Application with IPFS: A Step-by-Step Guide
Favicon
Step-by-Step Guide How to Store your data on IPFS with Spheron Browser SDK
Favicon
How to Use IPFS with Ethereum
Favicon
IPFS Bootcamp
Favicon
Incognfto: A Private NFT Gallery
Favicon
Innovating Web3 Infrastructure: Spheron X DripVerse Partnership
Favicon
How dAppling uses Filebase
Favicon
How to: IPNS on my Domain?
Favicon
Hosting Static Sites on IPFS
Favicon
Embracing Decentralised Web Hosting: A New Approach to Securing Web3 and DeFi Applications
Favicon
Setup IPFS images cache server in 5 min
Favicon
How to Add a Meson Cloud to Home Screen on iOS and Android?

Featured ones: