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 🙏

© 2025 – Pkg Stats / Ryan Hefner

castor-memcopy

v0.0.3

Published

Query Castor using an in-memory data copy.

Readme

node-castor-memcopy

Memcopy is an in-memory caching and processing extension for Castor. It allows fast query processing and more flexibility than regular Cassandra CQL queries. This module is designed for small datasets (< 10k rows).

Key features:

  • Caching of (partial) tables
  • Query data using chainable functions
  • Fulltext search
  • Usage is very similar to Castor Client, making it easy to build-in MemCopy in existing projects already using Castor.

Installation

Install using npm install castor-memcopy and npm install castor-client.

Usage

var Castor = require('castor-client');
var MemCopy = require('castor-memcopy');

var db = new Castor('localhost', 'keyspace');
var query = db.get('user').fields(['user_id', 'name', 'logins', 'bio']);

var copy = new MemCopy(query);
copy.get()
  .filter('name', /[0-9]/)
  .filter('logins', 1234, '>')
  .search('name', 'john')
  .orderBy('search_score', 'desc')
.then(function(rows) {
  console.log(rows.toArray());
  copy.bury(60);
});

When using MemCopy, you do not execute the Castor Client query itself. Instead, you make a copy using new MemCopy(query) and from there on use the copy. MemCopy will start loading all data from Cassandra directly after calling the constructor. All queries on the copy will not involve the database at all. When ready, you should always call destroy or bury. The destroy function will destroy the memory copy (after all clients are ready using it). This function does not take any arguments. The bury function will keep the copy in memory for the given number of seconds. If another MemCopy is created with the exact same query within this time, it will not load the data again from the database.

Retreiving data

Data is retreived using the get function. This function takes no arguments, in contract to the regular Castor.get. All filtering function can be chained to this function. The query is executed by calling then or execute. MemCopy provides the same set of functions on the resultset as Castor does. Both examples below are identical.

// Using Castor Client.

db.get('user')
  .filter('user_id', '...')
.then(function(rows) {
  while (rows.valid()) {
    var row = rows.current();
    rows.next();
  }
});
// Using Castor MemCopy.

var copy = new MemCopy(db.get('user'));
copy.get()
  .filter('user_id', '...')
.then(function(rows) {
  while (rows.valid()) {
    var row = rows.current();
    rows.next();
  }
  copy.bury(60);
});

Note that the MemCopy example will load the whole table from the database, since no filtering is specified in the query provided to new MemCopy(). The MemCopy example however, will not use the database in the next 60 seconds, no matter how many queries are executed.

Filtering

The code belows shows all filtering options.

var copy = new MemCopy(db.get('user'));
var query = copy.get();

// Simple filtering.
query.filter('user_id', '...');
query.filter('user_id', '...', '==='); // Default
query.filter('user_id', '...', '==');
query.filter('user_id', '...', '!==');
query.filter('user_id', '...', '!=');
query.filter('user_id', '...', '<');
query.filter('user_id', '...', '>');
query.filter('user_id', '...', '<=');
query.filter('user_id', '...', '>=');

// Regular expression matching.
query.filter('name', /[0-9]/); // Only names containing numbers.
query.filter('name', /[0-9]/, '!='); // No names containing numbers.

// Full text searching.
query.search('bio', 'friendly nice generous');
query.search(['interests', 'work'], 'hardworking teamplayer');
// Search function will add the column "search_score". Sort by relevance.
query.orderBy('search_score', 'desc');

// Ordering.
query.orderBy('name', 'asc');
query.orderBy('logins', 'desc');

// Limit results to top 10.
query.limit(10);

// Limit results with offset (result 10 to 15).
query.range(10, 5);

query.then(function(rows) {
  console.log('Found ' + rows.count() + ' rows');
  copy.destroy();
});

Clear cache

Use the clearCache function to clear all caches.

MemCopy.clearCache();