New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

vuex-cache

Package Overview
Dependencies
Maintainers
1
Versions
19
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

vuex-cache - npm Package Compare versions

Comparing version 0.3.1 to 1.0.0

31

index.js
'use strict';
var index = (function (store) {
var cache = Object.create(null);
store.cacheDispatch = function cacheDispatch() {
store.cache = new Map();
store.cache.dispatch = function () {
var type = arguments[0];
if (type in cache) {
return cache[type];
if (!store.cache.has(type)) {
store.cache.set(type, store.dispatch.apply(store, arguments));
}
cache[type] = store.dispatch.apply(store, arguments);
return cache[type];
return store.cache.get(type);
};
store.removeCache = function (actionName) {
if (actionName in cache) {
delete cache[actionName];
return true;
}
return false;
};
store.hasCache = function (key) {
return key in cache;
};
store.clearCache = function () {
for (var key in cache) {
delete cache[key];
}
return true;
};
});
module.exports = index;

2

package.json
{
"name": "vuex-cache",
"version": "0.3.1",
"version": "1.0.0",
"description": "cache vuex action",

@@ -5,0 +5,0 @@ "main": "index.js",

# vuex cache action
* * *
When vuex action fetch some data by request remote api, vuex-cache can store the action result, when next time the same action runs, it will not make a new request and just return the cached result.
## install
### Compatibility
Compatible with Vue2.x and Vuex2.x
### install
```bash

@@ -12,3 +13,3 @@ npm install vuex-cache

## usage
### usage

@@ -34,9 +35,15 @@ ```javascript

store.cacheDispatch('LIST')
store.cache.dispatch('LIST')
```
## api
### api
#### NOTICE: after update to 1.0.0, main api is different from the previous version 0.3.1
1.0.0 need your env has **Map** object, or import **Map** from babel-polyfill
thanks [VitorLuizC](https://github.com/VitorLuizC)
```javascript
store.cacheDispatch(ACTION_NAME)
store.cache.dispatch(ACTION_NAME)
```

@@ -48,3 +55,3 @@ params is same with vuex store.dispatch

```javascript
store.removeCache(ACTION_NAME)
store.cache.delete(ACTION_NAME)
```

@@ -54,3 +61,3 @@ remove cached action, will **not** remove the data in store. when call cacheDispatch with same type, the request in that action will run again.

```javascript
store.hasCache(ACTION_NAME)
store.cache.has(ACTION_NAME)
```

@@ -60,4 +67,4 @@ return bool if ACTION\_NAME has been cached

```javascript
store.clearCache()
store.cache.clear()
```
clear all cached keys
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