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

@pengqiangsheng/apicache

v1.0.2

Published

An ultra-simplified API response caching middleware for Koa using plain-english durations.

Downloads

6

Readme

Koa-apicache

An ultra-simplified API response caching middleware for Koa using plain-english durations.

Koa的api缓存中间件

基于apicache改造而成,拥有[email protected]以下所有的功能。

安装

yarn add @pengqiangsheng/apicache

使用文档

大体上分为三种使用方式:1.所有路由 2.某个路由实例下所有路由 3.某个具体的路由

const Koa = require('koa')
const app = new Koa()
const Router = require('@koa/router')
const apicache = require('@pengqiangsheng/apicache')
const cache = apicache.middleware
const router = new Router({
  prefix: '/api'
})

// 1.缓存所有api接口
app.use(cache('2 minutes'))

// 2.缓存/api下的所有接口
router.use(cache('2 minutes'))

// 3.指定一个接口缓存/api/pqs
router.get('/pqs', cache('2 minutes'), async ctx => {
  ctx.body = {
    name: 'pqs',
    pwd: '123456'
  }
})

app
  .use(router.routes())
  .use(router.allowedMethods())

测试说明

安装依赖

克隆本项目后,安装以下依赖:

"dependencies": {
  "@koa/router": "^8.0.8",
  "koa": "^2.11.0",
  "koa-logger": "^3.2.1",
  "nodemon": "^2.0.2",
  "redis": "^3.0.2"
}

运行测试脚本:

yarn test

or

npm run test

测试接口说明

测试Redis缓存需要安装Redis数据库,然后开启test.js第19行代码。

  • /api/pqs 无缓存
  • /api/ccc 无缓存
  • /api/cache/pqs 使用内存缓存
  • /api/cache/ccc 使用内存缓存
  • /api/cache/performance 查看使用内存缓存的命中率
  • /api/redis/ccc 使用Redis缓存
  • /api/redis/ccc 使用Redis缓存
  • /api/redis/performance 查看使用Redis缓存的命中率
  • /user/:collection/:id 添加分组缓存
  • /api/cache/index 查看分组情况
  • /api/cache/clear/:key? 清除分组

版权说明

本项目来源于apicache,如果有任何问题,请留下issue。