Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: swellstores/swell-node
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: v5.1.1
Choose a base ref
...
head repository: swellstores/swell-node
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: v5.2.0
Choose a head ref
  • 5 commits
  • 16 files changed
  • 3 contributors

Commits on Jul 27, 2023

  1. Bump word-wrap from 1.2.3 to 1.2.4 (#16)

    Bumps [word-wrap](https://github.com/jonschlinkert/word-wrap) from 1.2.3 to 1.2.4.
    - [Release notes](https://github.com/jonschlinkert/word-wrap/releases)
    - [Commits](jonschlinkert/word-wrap@1.2.3...1.2.4)
    
    ---
    updated-dependencies:
    - dependency-name: word-wrap
      dependency-type: indirect
    ...
    
    Signed-off-by: dependabot[bot] <support@github.com>
    Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
    dependabot[bot] authored Jul 27, 2023
    Copy the full SHA
    5bedf0c View commit details

Commits on Jul 28, 2023

  1. Feature: Add the ability to flush the cache (#17)

    - Add cache.flush().
    - Updated prettier (code format) settings
    - Moved cache store implementation to their own files
    - Added test coverage for individual cache stores
    - memory cache store uses a Map instead of an Object
    swellmike authored Jul 28, 2023
    Copy the full SHA
    ab92697 View commit details

Commits on Jul 31, 2023

  1. Feature: Trigger cache flush on $flushCache push message (#18)

    * add cache-flush trigger
    
    * add prettier dev dependency
    
    * update jest config, auto-reset stubs
    swellmike authored Jul 31, 2023
    Copy the full SHA
    fb3a9d2 View commit details

Commits on Aug 1, 2023

  1. Copy the full SHA
    d2afa99 View commit details
  2. 5.2.0

    swellmike committed Aug 1, 2023
    Copy the full SHA
    1022173 View commit details
1 change: 1 addition & 0 deletions .prettierignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
node_modules/
8 changes: 0 additions & 8 deletions .prettierrc

This file was deleted.

18 changes: 18 additions & 0 deletions .prettierrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{
"arrowParens": "always",
"bracketSameLine": false,
"bracketSpacing": true,
"endOfLine": "lf",
"overrides": [
{
"files": "*.mjml",
"options": { "parser": "html" }
}
],
"printWidth": 80,
"semi": true,
"singleQuote": true,
"tabWidth": 2,
"trailingComma": "all",
"useTabs": false
}
4 changes: 3 additions & 1 deletion jest.config.json
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
{
"testEnvironment": "node"
"testEnvironment": "node",
"clearMocks": true,
"restoreMocks": true
}
92 changes: 24 additions & 68 deletions lib/cache.js → lib/cache/index.js
Original file line number Diff line number Diff line change
@@ -1,49 +1,48 @@
const EventEmitter = require('events');
'use strict';

const crypto = require('crypto');

const { CacheStoreFactory } = require('./storage/cache_store_factory');

const DEFAULT_STORAGE = 'shared-memory';
const DEFAULT_INDEX_LIMIT = 1000;

class Cache extends EventEmitter {
class Cache {
constructor(clientId, options) {
super();

this.versions = null;
this.indexes = null;
this.storage = null;
this.env = null;

options = options || {};
if (typeof options === 'string') {
options = { path: options };
}

// Pre-emptive env setting
this.env = options.env;

this.params = {
clientId: clientId,
path: options.path ? String(options.path) : '',
storage: options.storage || DEFAULT_STORAGE,
indexLimit: options.indexLimit || DEFAULT_INDEX_LIMIT,
};

switch (this.params.storage) {
case 'memory':
this.storage = new MemoryStorage();
break;
case 'shared-memory':
this.storage = new SharedMemoryStorage();
break;
default:
throw new Error(this.params.storage + ' storage is not currently supported');
}
// Initialize environment setting
this.env = options.env;

// Initialize cache storage
this.cacheStore = CacheStoreFactory.getCacheStore(this.params.storage);

// Initialize cache contents
this.flush();
}

setEnv(env) {
this.env = env;
}

/**
* Flushes the cache.
*/
flush() {
this.cacheStore.flush();
this.reset();
}

get(url, data) {
data = data || null;

@@ -272,7 +271,7 @@ class Cache extends EventEmitter {
// Get cache content
getCache() {
const cachePath = this.getPath.apply(this, arguments);
const cacheContent = this.storage.read(cachePath);
const cacheContent = this.cacheStore.read(cachePath);
if (cacheContent !== undefined) {
return JSON.parse(cacheContent);
}
@@ -284,14 +283,14 @@ class Cache extends EventEmitter {
const cacheContent = JSON.stringify(content);
const cacheSize = cacheContent.length;

this.storage.write(cachePath, cacheContent);
this.cacheStore.write(cachePath, cacheContent);

return cacheSize;
}

// Clear a cache path
clearCache(cachePath) {
this.storage.remove(cachePath);
this.cacheStore.remove(cachePath);
}

// Get array of collections affected by a result
@@ -309,47 +308,4 @@ class Cache extends EventEmitter {
}
}

// Memory used by this instance only
class MemoryStorage {
memory = {};

read(key) {
return this.memory[key];
}

write(key, value) {
this.memory[key] = value;
}

remove(key) {
delete this.memory[key];
}
}

// Memory used by all instances in this process
class SharedMemoryStorage {
memory = {};

constructor() {
if (!SharedMemoryStorage.memory) {
SharedMemoryStorage.memory = {};
}
this.memory = SharedMemoryStorage.memory;
}

read(key) {
return this.memory[key];
}

write(key, value) {
this.memory[key] = value;
}

remove(key) {
delete this.memory[key];
}
}

module.exports = Cache;
module.exports.MemoryStorage = MemoryStorage;
module.exports.SharedMemoryStorage = SharedMemoryStorage;
Loading