Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Build data cache extension on hyper connect #436

Open
tripott opened this issue Feb 3, 2022 · 1 comment
Open

Build data cache extension on hyper connect #436

tripott opened this issue Feb 3, 2022 · 1 comment
Assignees

Comments

@tripott
Copy link
Contributor

tripott commented Feb 3, 2022

transferred from hyper63/hyper-cloud#485

@tripott tripott added this to the Z milestone Feb 3, 2022
@tripott
Copy link
Contributor Author

tripott commented Feb 3, 2022

Tom made some progress on a utility cache counter increment method

import { connect } from 'hyper-connect'
const hyper = connect(process.env.HYPER)

const increment = result => result.count ? result.count + 1 : 1
const update = name => count => hyper.cache.set(name, { count })
const resolve = x => result => result.ok ? x : Promise.reject({ status: 500, error: 'Could not find cache' })
const decrement = result => result.count ? result.count - 1 : 0

export function incrementCounter(type) {
  return function (x) {
    return hyper.cache.get(`${type}-counter`)
      .then(increment)
      .then(update(`${type}-counter`))
      .then(resolve(x))
  }

}

export function decrementCounter(type) {
  return function (x) {
    return hyper.cache.get(`${type}-counter`)
      .then(decrement)
      .then(update(`${type}-counter`))
      .then(resolve(x))
  }

}

@tripott tripott removed this from the Z milestone Feb 9, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Status: 📋 Backlog
Development

No branches or pull requests

2 participants