Skip to content

Commit

Permalink
Revert cache implementation becuase of unwanted side effects
Browse files Browse the repository at this point in the history
Signed-off-by: Axel Boberg <[email protected]>
  • Loading branch information
axelboberg committed Mar 24, 2024
1 parent c72b6a3 commit 21e33c2
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 22 deletions.
1 change: 1 addition & 0 deletions api/classes/Cache.js
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ class Cache {
return that rather than starting a new request
*/
if (
value &&
typeof value === 'object' &&
value.__status === 'pending' &&
value.__promise
Expand Down
9 changes: 1 addition & 8 deletions api/items.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,6 @@ const variables = require('./variables')
const MissingArgumentError = require('./error/MissingArgumentError')
const InvalidArgumentError = require('./error/InvalidArgumentError')

const Cache = require('./classes/Cache')

const ITEM_CACHE_MAX_ENTRIES = 10
const itemCache = new Cache(ITEM_CACHE_MAX_ENTRIES)

/**
* Create a new id for an item
* that is unique and doesn't
Expand Down Expand Up @@ -100,9 +95,7 @@ exports.applyItem = applyItem
* @returns { Promise.<Item> }
*/
function getItem (id) {
return itemCache.cache(`${id}::${state.getCurrentRevision()}`, () => {
return commands.executeCommand('items.getItem', id)
})
return commands.executeCommand('items.getItem', id)
}
exports.getItem = getItem

Expand Down
23 changes: 9 additions & 14 deletions api/state.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,6 @@ const merge = require('../shared/merge')
const commands = require('./commands')
const events = require('./events')

const Cache = require('./classes/Cache')

const STATE_CACHE_MAX_ENTRIES = 10
const stateCache = new Cache(STATE_CACHE_MAX_ENTRIES)

/**
* Keep a local
* copy of the state
Expand All @@ -25,17 +20,17 @@ let state
* this is used to ensure
* that the state is kept
* up-to-date
*
* Please note that this
* value only will be updated
* if there are listeners for
* state changes attached by
* the current process
*
* @type { Number }
*/
let revision = 0

/**
* Get the current local
* revision of the state
* @returns { Number }
*/
exports.getCurrentRevision = () => revision

/**
* Get the full remote state
* @returns { Promise.<any> }
Expand Down Expand Up @@ -122,13 +117,13 @@ exports.apply = apply
* @returns { Promise.<State> }
*/
async function get (path) {
const newState = await getRemoteState(path)
if (!path) {
const newState = await getRemoteState()
revision = newState._revision
state = newState
return state
} else {
return stateCache.cache(`${path}::${revision}`, () => getRemoteState(path))
return newState
}
}
exports.get = get
Expand Down

0 comments on commit 21e33c2

Please sign in to comment.