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

ficache

v0.2.0

Published

The secondary life cycle cacher of the database

Downloads

9

Readme

ficache

数据库二级缓存.

  • 模型查询设置缓存
  • 自动过期
  • 数据更新及时删除缓存
  • 多表查询设置缓存
  • 执行日志

支持查询方法

  • findOne
  • findAll
  • count
  • find
  • findAndCountAll

支持更新方法

  • create
  • update
  • destroy

快速使用

建议搭配 sequelize-base 使用

创建 model

const Cacher = require('ficache');
const Base = require('sequelize-base');
const Sequelize = require('sequelize');
const {INTEGER, STRING, CHAR} = DataTypes;
 
const pool = new Sequelize(Object.assign(config, {
  logging: (msg) => log.info(msg),
}));
 
const attributes = {
  userId: {type: INTEGER(11), primaryKey: true, autoIncrement: true, field: 'user_id'},
  account: {type: STRING(30), comment: 'accout', allowNull: false, unique: true, field: 'accout'},
  nickName: {type: STRING(30), comment: 'nickName', allowNull: false, field: 'nickname'},
  password: {type: STRING(32), comment: '密码', allowNull: false, field: 'password'},
  invalid: {type: CHAR(1), defaultValve: 'N', comment: '是否有效', field: 'invalid'},
};
 
const UserEntity = pool.define('User', attributes, {
  timestamps: true,
  freezeTableName: true,
  updatedAt: 'mtime',
  createdAt: 'ctime',
  tableName: 'bas_user',
  charset: 'utf8mb4',
  comment: '用户表',
});
 
class UserModel extends Base {
 
  constructor(opts) {
    super(opts);
  }
 
  static getInstance(opts = {
      entity: UserEntity,
      cacher: new Cacher({
        dbClient: pool,
        cacheClient: redis.client,
        model: UserEntity,
        logger: log,
      }),
    }) {
    if (!this.instance) {
      this.instance = new UserModel(opts);
    }
    return this.instance;
  }
 
}
 
module.exports = UserModel;

查询缓存

'use strict';

const userModel = require('../model/userModel');

exports.getUsers = async () => {
  return userModel.findAll();
};

第一次查询会从数据库中获取数据,并设置缓存,之后查询从缓存中获取

Executed (cache): key/sequelize_base_cache:cache:base_user:7afe7351e3372bfa3dbdbd63d4adeb2059ef2c88 {"method":"findAll","params":[{"where":{"invalid":"N"},"attributes":[]}]}

删除缓存

'use strict';

const userModel = require('../model/userModel');

exports.addUser = async (body) => {
  return userModel.create(body);
};

执行此操作会触发bas_user相关的key删除

Executed (delCache): mapKey/sequelize_base_cache:cache_keymap:bas_user

Author

Polix © Ricky 泽阳, Released under the MIT License.