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

memcing

v1.0.0

Published

An in-memory key-value caching application with RESTful API

Downloads

13

Readme

Memcing

NPM Build Status

Memcing is an in-memory key-value caching application with RESTful API.

Installation

npm install memcing

Usage

Interactive mode

npm start

Add an entry (add hello world) and see http://localhost:12080/entries/hello

Help

./memcing -help
  Options:
    -i                 : Enable interactive mode.
    -listen-http       : Listen HTTP requests. Default; 0.0.0.0:12080
    -load-file         : Load a command file.

    -cache-limit       : Cache size limit in bytes. Default (128MB); 134217728
    -entry-limit       : Entry size limit in bytes. Default (1KB); 1024
    -vacuum-delay      : Delay in seconds for vacuum. Default; 30
    -eviction          : Enable eviction mode.

    -debug             : Enable debug mode.
    -verbose           : Set verbose message level. Default; 1
    -help              : Display help and exit.

  stdin:
    -cmd               : Enable command mode for stdin.
    -csv               : Enable CSV mode for stdin.
    -csv-delimiter     : CSV delimiter (char or `tab`). Default; ,
    -csv-field-key     : Key field index on CSV. Default; 1
    -csv-field-filter  : Include fields on CSV. Default (all); null
                         Example; -csv-field-filter 1,2

  Interactive mode commands:
    get key
    set key value [expire = 0]
    add key value [expire = 0]
    increment key [amount = 1]
    decrement key [amount = 1]
    delete key
    drop
    dump
    stats
    vacuum
    exit

Examples

Interactive Mode

./memcing -load-file ../test/cmds-lf.txt -i -listen-http

Reads commands from cmds-lf.txt then switch to interactive mode and listen ttp requests. The cached data will be available for REPL and RESTful API.

For RESTful API performance tests;

ab -n 10000 http://localhost:12080/entries/hello
ab -n 10000 -c 100 http://localhost:12080/entries/hello

Postal Code Service Example

You can easily create a postal code service;

wget -qO zip-codes.zip http://download.geonames.org/export/zip/US.zip && \
unzip -p zip-codes.zip US.txt | \
cat | \
./memcing -listen-http -csv -csv-delimiter tab -csv-field-key 2 -csv-field-filter 1,3,4,5,6,10,11

See http://localhost:12080/entries/78729

{
  "key":"78729",
  "val":"[\"US\",\"Austin\",\"Texas\",\"TX\",\"Williamson\",\"30.4521\",\"-97.7688\"]",
  "ts":1401417873489,
  "expTS":0
}

If you want to include other countries see http://download.geonames.org/export/zip/ and change the part (US.zip and US.txt) of the command at above.

RESTful API

RESTful API is still under development. For the current implementations see Implementations

  • Use application/x-www-form-urlencoded for request method.
  • Use val query parameter for value.
  • Use exp query parameter for expiration.

PUT

/entries/{KEY}

PUT method represent the set command.

Examples:

curl -X PUT -d "val=world" http://localhost:12080/entries/hello
curl -X PUT -d "val=world&exp=10" http://localhost:12080/entries/bye

POST

/entries/{KEY}

POST method represent the add command.

Examples:

curl -X POST -d "val=1" http://localhost:12080/entries/counter

GET

/entries
/entries/{KEY}

GET method represent the get command.

Examples:

curl http://localhost:12080/entries
curl http://localhost:12080/entries/hello

DELETE

/entries
/entries/{KEY}

DELETE method represent the delete or the drop command.

Examples:

curl -X DELETE http://localhost:12080/entries/hello
curl -X DELETE http://localhost:12080/entries

Notes

  • It is 'originally' developed for code exercise. The requirements were; non-persistent, non-durable and supporting eviction.

Implementations

  • [x] Interactive mode
  • [ ] RESTful API
    • [x] GET
      • [x] Collection (/entries)
      • [x] Element (/entries/{KEY})
    • [ ] PUT
      • [ ] Collection (/entries)
      • [x] Element (/entries/{KEY})
    • [ ] POST
      • [ ] Collection (/entries)
      • [x] Element (/entries/{KEY})
    • [x] DELETE
      • [x] Collection (/entries)
      • [x] Element (/entries/{KEY})

###License

Licensed under The MIT License (MIT)
For the full copyright and license information, please view the LICENSE.txt file.