Skip to content

Commit

Permalink
Ensure the LocalStroage keys are valid.
Browse files Browse the repository at this point in the history
Also update the cache key name.
  • Loading branch information
cotes2020 committed Jun 23, 2020
1 parent afccb14 commit 4d4e9a0
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions assets/js/_utils/pageviews.js
Original file line number Diff line number Diff line change
Expand Up @@ -94,8 +94,8 @@ var getInitStatus = (function() {

var PvCache = (function() {
const KEY_PV = "pv";
const KEY_CREATION = "pv-created-date";
const KEY_PV_TYPE = "pv-type";
const KEY_CREATION = "pv_created_date";
const KEY_PV_TYPE = "pv_type";

var PvType = {
ORIGIN: "origin",
Expand Down Expand Up @@ -148,6 +148,13 @@ var PvCache = (function() {
},
newerThan: function(pv) {
return PvCache.getAllPagevies() > pv.totalsForAllResults["ga:pageviews"];
},
inspectKeys: function() {
if (localStorage.getItem(KEY_PV) == null
|| localStorage.getItem(KEY_PV_TYPE) == null
|| localStorage.getItem(KEY_CREATION) == null) {
localStorage.clear();
}
}
};

Expand Down Expand Up @@ -184,6 +191,8 @@ $(function() {

if ($('.pageviews').length > 0) {

PvCache.inspectKeys();

let cache = PvCache.getData();

if (cache) {
Expand Down

0 comments on commit 4d4e9a0

Please sign in to comment.