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

meddelare-server

Package Overview
Dependencies
Maintainers
1
Versions
22
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

meddelare-server - npm Package Compare versions

Comparing version 1.2.2 to 1.3.0

52

lib/social-buttons-server-middleware.js
var express = require("express");
var Promise = require("bluebird");
var request = require("request");
var cache = require("memory-cache");
// Cache results in memory -- but keep good and bad (error thrown) results for different periods of time.
var LOCAL_CACHE_TIME_GOOD_RESULT = 4 * 60 * 1000,
LOCAL_CACHE_TIME_BAD_RESULT = 1 * 60 * 1000;
// Return this count if none was found or an error was thrown.
var DEFAULT_UNKNOWN_COUNT = -1;
// How many minutes should we cache the results for a given request

@@ -116,6 +124,37 @@ var CACHE_TIME = process.env.CACHE_TIME || 4 * 60;

return -1;
throw err;
});
}
function createCacheKey(url, network) {
return network + " '" + url + "'";
}
function getCachedOrRetrieveCount(url, network) {
var cacheKey = createCacheKey(url, network);
return Promise.resolve(cache.get(cacheKey))
.then(function(cachedResult) {
if (typeof cachedResult !== "undefined" && cachedResult !== null) {
console.log(cacheKey, "from cache", cachedResult);
return cachedResult;
}
return retrieveCount(url, network)
.tap(function(uncachedResult) {
console.log(cacheKey, "fetched good result", uncachedResult);
cache.put(cacheKey, uncachedResult, LOCAL_CACHE_TIME_GOOD_RESULT);
})
.catch(function(err) {
console.error(cacheKey, "fetched bad result", err);
cache.put(cacheKey, DEFAULT_UNKNOWN_COUNT, LOCAL_CACHE_TIME_BAD_RESULT);
return DEFAULT_UNKNOWN_COUNT;
});
});
}
function retrieveCounts(url, networks) {

@@ -128,3 +167,3 @@ // Create an object of callbacks for each of the requested networks It is

networks.forEach(function(network) {
networksToRequest[network] = retrieveCount(url, network);
networksToRequest[network] = getCachedOrRetrieveCount(url, network);
});

@@ -222,2 +261,11 @@

// Perhaps it's futile to try and clean up before/exit, but one can try.
process
.once("beforeExit", function() {
cache.clear();
})
.once("exit", function() {
cache.clear();
});
module.exports = router;

3

package.json
{
"name": "meddelare-server",
"version": "1.2.2",
"version": "1.3.0",
"description": "Install custom social share counters on your website with your own hosted solution, which only makes a single API request and loads minimal or zero assets to display the counters.",

@@ -18,2 +18,3 @@ "homepage": "http://meddelare.com/",

"express": "^4.12.4",
"memory-cache": "^0.1.4",
"morgan": "^1.5.3",

@@ -20,0 +21,0 @@ "request": "~2.33.0"

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