Skip to content

Instantly share code, notes, and snippets.

@jkyberneees
Last active June 19, 2018 10:52
Show Gist options
  • Select an option

  • Save jkyberneees/8bd08897ae050cf603200b6ec8c67dd0 to your computer and use it in GitHub Desktop.

Select an option

Save jkyberneees/8bd08897ae050cf603200b6ec8c67dd0 to your computer and use it in GitHub Desktop.
// on application instance start, init near cache Map
const {Client, Config} = require('hazelcast-client')
const nearCachedMapName = 'my-holy-fast-map'
const cfg = new Config.NearCacheConfig()
cfg.name = nearCachedMapName
cfg.invalidateOnChange = true
cfg.nearCacheConfigs[nearCachedMapName] = cfg
const hazelcast = await Client.newHazelcastClient(cfg)
const locations = hazelcast.getMap(nearCachedMapName)
// on application instance start, fill map with locations once
if (await locations.size() === 0) {
(await LocationsService.findAll()).forEach(location => {
locations.put(location._id, location)
})
}
// on location change
await locations.put(location._id, location)
// on locations retrieval "GET /locations"
await locations.values()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment