Last active
June 19, 2018 10:52
-
-
Save jkyberneees/8bd08897ae050cf603200b6ec8c67dd0 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // 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