npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

dragonfly-redis-prisma-cache

v1.0.0

Published

A Cache middleware for dragonfly (faster then redis), which still can be used with redis.

Downloads

9

Readme

dragonfly-redis-prisma-cache

A Cache middleware for dragonfly (faster then redis), which still can be used with redis.

Install Package

npm i Tomato6966/dragonfly-redis-prisma-cache

Why should u use this?

First you should always cache a database for GET-QUERY REQUESTS. This way you reduce traffic on a database. Prisma is very great as this way you can use postgresql / mongodb / mysql... with the same wrapper! and still are able to use this cache with all dbs!

It's the most optimal, when beeing used with dragonfly Because dragonfly is like redis, yet it has multithreading and can handle hundred of thousands requests at the same time!

This package is better then other cache wrappers cause it invalidates only thigns related to what you change!

You can still use it with regular redis tho.

Why no invalidation based on cache size?

  • dragonfly has that built in

Performance improvements:

  • No cache at all: 2-4ms for get query requests based on: ~10 requests / Seconds and while beeing on localhost with citus psql (psql but threaded)
  • Cache via psql: 1.4-2.5ms --> However that cache is not as efficient as the one from dragonfly since dragonflys storage engine is OP
  • Cache via dragonfly: 0.8-1ms for all get query (if they not set in cache yet, then it's a psql request time of 2-4ms) (aka this package ;))

Check this Video for example

https://user-images.githubusercontent.com/68145571/193469577-47b677d6-80ee-47fd-ad2a-b5645d2332a4.mp4

How to install and use dragonfly

  1. download it
wget https://github.com/dragonflydb/dragonfly/releases/latest/download/dragonfly-x86_64.tar.gz && tar -xvzf dragonfly-x86_64.tar.gz && rm dragonfly-x86_64.tar.gz
  1. start it (host, port, max memory in bytes, auto storage in a single file with autosavings every 30mins)
./dragonfly-x86_64 --logtostderr --requirepass=youshallnotpass --bind localhost --port 6739 --hz=10 --save_schedule "*:30" --maxmemory 4294967296 --dbfilename dump.rdb
  1. you can paste all of that inside a "startdragonfly.sh" file and start that file via pm2 / screen etc.
echo "./dragonfly-x86_64 --logtostderr --requirepass=youshallnotpass --bind localhost --port 6739 --hz=10 --save_schedule "*:30" --maxmemory 4294967296 --dbfilename dump.rdb" > startdragonfly.sh
chmod +rwx startdragonfly.sh
# e.g. with pm2
pm2 start --name dragonflycache ./startdragonfly.sh

Use Package

import { PrismaClient } from '@prisma/client'
import { prismaDragonflyRedisCache } from 'dragonfly-redis-prisma-cache';

const prisma = new PrismaClient();

prisma.$use(prismaDragonflyRedisCache({
    storageOptions:{
        // connection hostname/ipaddress
        host: "localhost",
        // Port for the dragonfly instance
        port: 6379,
        // your password don't provide it if not needed
        password: "youshallnotpass",
        // when to cancel the requests after X milli-seconds
        timeout: 2000,
        /** If undefined | <= 0 then no Pool will be used */
        min_conn: 100,
        // dragonfly can handle hundred of thousands connections at once
        max_conn: 1000,
        //  tls: {
        //    key: Buffer.from("key_string"),
        //    cert: Buffer.from("cert_string"),
        //  };
    },
    useAllModels: true, //overwrites toCache
    defaultCacheActions: [ "findUnique", "findFirst", "findMany", "count", "aggregate", "groupBy", "findRaw", "aggregateRaw" ],
    defaultTTL: 0, // amount of ttl for on default
    toCache: [
        {                      
            model: 'Users',                
            actions: ['findFirst', "findUnique", "count"],           
            ttl: 60,                       
            keyPrefix: 'usrs'             
        },
        {
            model: 'Users',
            actions: ['findFirst', "findUnique", "count"],
        }
    ]
}));

export default prisma;

example how i do it:

const { getRedisDataOfURL, prismaDragonflyRedisCache } = require("dragonfly-redis-prisma-cache");
prisma.$use(prismaDragonflyRedisCache({
    storageOptions: {
        ...(getRedisDataOfURL("redis://:[email protected]:6739")),
        min_conn: 100,
        max_conn: 1000,
    },
    useAllModels: true,
    defaultCacheActions: [ "findUnique", "findFirst", "findMany", "count", "aggregate", "groupBy", "findRaw", "aggregateRaw" ],
}));

Devnote: Building and formatting

npm run build
npm run lint
npm run format

About Documatic!

Documatic is a search engine for your codebase; Ask documatic a question and find relevant code snippets and insights in seconds.

https://www.documatic.com/ Documatic acts as a search engine for your codebase; once you describe what you're looking for, Documatic pulls up related code or documentation making it easier to find what you're looking for in seconds!

Not sitting next to each other? No problem. Ask Documatic questions of your codebase to learn and understand your code in seconds. Documatic is the team member you wish you had

Our Visual studio Code extension: https://marketplace.visualstudio.com/items?itemName=Documatic.documatic https://cdn.discordapp.com/attachments/926110059782615071/1037404343470661713/Documatic_sh6hrz.gif