cache.js 582 B

12345678910111213141516171819202122232425262728
  1. function getCache(key, hour = 4) {
  2. let k = 'chche:' + key
  3. let ct = Date.parse(new Date()) / 1000;
  4. let ca = my.getStorageSync({ 'key': k }).data
  5. if (ca) {
  6. if ((ct - ca.time) < (hour * 60 * 60)) {
  7. return ca.value
  8. }
  9. return false
  10. }
  11. return false
  12. }
  13. function setCache(key, data = {}, hour = 4) {
  14. let k = 'chche:' + key
  15. let ct = Date.parse(new Date()) / 1000;
  16. my.setStorageSync({ 'key': k, 'data': { 'time': ct, 'value': data } })
  17. }
  18. const CacheKeys = {
  19. '': ""
  20. }
  21. module.exports = {
  22. getCache: getCache,
  23. setCache: setCache,
  24. CacheKeys: CacheKeys
  25. }