1.1.1 • Published 10 months ago

cachero v1.1.1

Weekly downloads
-
License
MIT
Repository
-
Last release
10 months ago

Cachero

Enable cache all CRUD operations, a library for Node.js.

Cachero Logo

const { createCachero } = require('cachero')

const cachero = createCachero()

await cachero.setting({ table, queryRunner })

const result = await cachero.select()

Installation

NPM

$ npm install cachero

Features

  • Easy CRUD caching
  • Very low latency
  • Minimize the use of DB
  • Reduces server load
  • Look-Aside + Write-Back caching
  • Easier syntax than most ORM

Example

Express Example

const express = require('express');
const { createCachero } = require('cachero')
const { createClient } = require('redis')
const { Pool } = require('pg')

const pool = new Pool()
const redis = createClient()

const app = express()
const postCachero = createCachero()

app.get('/post', function (req, res) {
  const cachedKey = req.originalUrl

  const result = await postCachero.select({ 
    column: ['*']
  }, cachedKey)

  res.json(result)
})

app.listen(3000, async () => {
  await pool.connect()
  await redis.connect()

  await postCachero.setting({ table: 'post', refKey: 'id', queryRunner: pool, redis })
});

More Usage

postCachero.select({
  column: [
    'post.*',
    'COALESCE(ARRAY_LENGTH(liked_user, 1), 0) AS like_count',
    'users.name AS owner_name'
  ],
  order: ['like_count DESC', 'created_at DESC'],
  where: {
    condition1: ['id', '=', '0'],
    condition2: ['like_count', '>=', '10'],
    result: ['condition1', '&&', 'condition2']
  },
  join: 'users ON post.maker_id = users.id',
  limit: 0,
  offset: 0
})

Create, Update, Delete, Scheduler Example

// Create, Update, Delete have to send a refKey

cachero.create({ id:'0', title:'new data' })

cachero.update({ id:'0', title:'update data' })

cachero.delete({ id: '0' })

cachero.scheduler([[12,0]])

setting

  • You shuold setting before use cachero
  • refKey is used as a reference value for saving, updating, and deleting data
  • You don't have to send preloadData, redis
  • If you send preloadData, it's saved and used before cachero get the data
  • If you send redis, the data is also saved in redis when data is saved in memory, which greatly increases stability

select

  • After you get all the columns of multiple data into * or table.*, if you get the detailed data of one of them again, cachero don't run sql query, so it's good for performance.
  • cachedKey is used to determine whether the value is valid when reading multiple data. Use it when you get multiple data, if you get the detailed data of one of them again, it doesn't have to be used

delete

  • You can erase only one specific value with an id value, but even if you send another key value, it erases all that data

License

MIT

1.1.1

10 months ago

1.0.2

10 months ago

1.1.0

10 months ago

1.0.9

10 months ago

1.0.8

10 months ago

1.0.6

10 months ago

1.0.5

10 months ago

1.0.4

10 months ago

1.0.3

10 months ago

1.0.11

10 months ago

1.0.10

10 months ago

1.0.14

10 months ago

1.0.13

10 months ago

1.0.12

10 months ago

1.0.1

10 months ago

1.0.0

10 months ago