1 | /**
|
2 | * @function
|
3 | * @public
|
4 | *
|
5 | * Initiate a cache
|
6 | *
|
7 | * @param {Hapi.Server} server The created server instance
|
8 | * @param {Object|boolean} [opts=false] The instance its options
|
9 | * @returns {Object|false} The cache instance
|
10 | */
|
11 | function create (server, opts = false) {
|
12 | return opts && server.cache(opts === true ? { segment: 'keycloakJwt' } : opts)
|
13 | }
|
14 |
|
15 | /**
|
16 | * @function
|
17 | * @public
|
18 | *
|
19 | * Get value out of cache by key.
|
20 | * Just if cache is initiated.
|
21 | *
|
22 | * @param {Object} The cache instance
|
23 | * @param {*} key The key to be searched
|
24 | */
|
25 | function get (cache, key) {
|
26 | return cache ? cache.get(key) : false
|
27 | }
|
28 |
|
29 | /**
|
30 | * @function
|
31 | * @public
|
32 | *
|
33 | * Set value specified by key in cache.
|
34 | * Just if cache is initiated.
|
35 | *
|
36 | * @param {Object} The cache instance
|
37 | * @param {Array} rest The arguments passed to hapi its `cache.set`
|
38 | */
|
39 | async function set (cache, ...rest) {
|
40 | cache && await cache.set(...rest)
|
41 | }
|
42 |
|
43 | module.exports = {
|
44 | create,
|
45 | get,
|
46 | set
|
47 | }
|