Guest User

Untitled

a guest
Jun 20th, 2018
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.73 KB | None | 0 0
  1. // on application instance start, init near cache Map
  2. const {Client, Config} = require('hazelcast-client')
  3. const nearCachedMapName = 'my-holy-fast-map'
  4.  
  5. const cfg = new Config.NearCacheConfig()
  6. cfg.name = nearCachedMapName
  7. cfg.invalidateOnChange = true
  8. cfg.nearCacheConfigs[nearCachedMapName] = cfg
  9.  
  10. const hazelcast = await Client.newHazelcastClient(cfg)
  11. const locations = hazelcast.getMap(nearCachedMapName)
  12.  
  13. // on application instance start, fill map with locations once
  14. if (await locations.size() === 0) {
  15. (await LocationsService.findAll()).forEach(location => {
  16. locations.put(location._id, location)
  17. })
  18. }
  19.  
  20. // on location change
  21. await locations.put(location._id, location)
  22.  
  23. // on locations retrieval "GET /locations"
  24. await locations.values()
Add Comment
Please, Sign In to add comment