Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

cachepuncher

Package Overview
Dependencies
Maintainers
1
Versions
3
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

cachepuncher

Punch browser caching right in the cache

  • 0.1.3
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
0
decreased by-100%
Maintainers
1
Weekly downloads
 
Created
Source

cachepuncher

Punch browser caching straight in the cache!

Cockpuncher (the Onion Movie)

Don't you just hate browsers that cache overly aggressively? Yes, I'm looking at you Chrome and Mobile Safari, you rule breaking maniacs. It's time for the cache puncher!

This tiny piece of software will generate a unique time-based code that you can inject into your URLs whenever you need to do some ajax or image loading. It guarantees no two codes are the same, even if generated within the same millisecond. It comes with a few options to further shrink down the code if you care a lot about saving a few extra precious bytes.

Installation

Install with component(1):

$ component install wizcorp/cachepuncher

The output format

Cache puncher always returns a code that is URL friendly, so no further URL escaping is needed (though it won't break if you do encode it). The output format is a numerical (base 2-36, you choose) timestamp, followed by an iteration number to avoid collisions within a single timestamp. You may change the output rules for each punch, and cache puncher will still guarantee uniqueness for each generated code.

API

A cache puncher instance has only one function that will keep generating unique codes: punch.

Simple example

Example:

var punch = require('cachepuncher').punch;

var image = new Image();
image.src = 'http://example.com/punch.jpg?rand=' + punch();

Arguments

The punch function takes arguments:

var code = punch({
	msec: true,
	base: 16,
	epoch: new Date(2013, 0, 1, 0, 0, 0)
});
optiontypedefaultmeaning
msecbooleanfalseOutput milliseconds. Useful (but not required) if you need many codes per second.
basenumber10Output the code in base-N, eg 16 for hex. Must be between 2 and 36.
epochDateunix epochSet a custom epoch, to lower the output number.

Cache puncher instances

You can use the default cache puncher as shown in the example above, or you can create your own with default settings for the punch function.

Example:

var puncher = require('cachepuncher');
var punch = puncher.create({ base: 36 });  // output in base 36 by default

var image = new Image();
image.src = 'http://example.com/punch.jpg?rand=' + punch();

About the name

It's a wink to the fake movie Cock Puncher starring the awesome Steven Seagal, featured in the hilarious The Onion Movie. I wish they made Cock Puncher an actual movie. Please don't sue me for using the image, and don't punch my cock either please.

License

MIT

FAQs

Package last updated on 27 Nov 2014

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc