Struct: endpoint-discovery.EndpointCache

import "../ibm-cos-sdk-go-v2/service/internal/endpoint-discovery"

Overview

EndpointCache is an LRU cache that holds a series of endpoints based on some key. The data structure makes use of a read write mutex to enable asynchronous use.

Implemented Interfaces

types.AnalyticsFilter, v4.HTTPPresigner, s3.HTTPPresignerV4, types.MetricsFilter, s3.PresignPost, arn.S3ObjectLambdaARN, types.SelectObjectContentEventStream

Constructor Functions collapse

Method Summary collapse

Function Details

func NewEndpointCache(endpointLimit int64) *EndpointCache

NewEndpointCache will return a newly initialized cache with a limit of endpointLimit entries.



21
22
23
24
25
26
// File 'service/internal/endpoint-discovery/cache.go', line 21

func NewEndpointCache(endpointLimit int64) *EndpointCache { return &EndpointCache{ endpointLimit: endpointLimit, endpoints: sync.Map{}, } }

Method Details

func (c *EndpointCache) Add(endpoint Endpoint)

Add is a concurrent safe operation that will allow new endpoints to be added to the cache. If the cache is full, the number of endpoints equal endpointLimit, then this will remove the oldest entry before adding the new endpoint.



66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
// File 'service/internal/endpoint-discovery/cache.go', line 66

func (c *EndpointCache) Add(endpoint Endpoint) { // de-dups multiple adds of an endpoint with a pre-existing key if iface, ok := c.endpoints.Load(endpoint.Key); ok { e := iface.(Endpoint) if e.Len() > 0 { return } } size := atomic.AddInt64(&c.size, 1) if size > 0 && size > c.endpointLimit { c.deleteRandomKey() } c.endpoints.Store(endpoint.Key, endpoint) }

func (c *EndpointCache) Get(endpointKey string) (WeightedAddress, bool)

Get will retrieve a weighted address based off of the endpoint key. If an endpoint should be retrieved, due to not existing or the current endpoint has expired the Discoverer object that was passed in will attempt to discover a new endpoint and add that to the cache.



55
56
57
58
59
60
61
// File 'service/internal/endpoint-discovery/cache.go', line 55

func (c *EndpointCache) Get(endpointKey string) (WeightedAddress, bool) { endpoint, ok := c.get(endpointKey) if !ok { return WeightedAddress{}, false } return endpoint.GetValidAddress() }

func (c *EndpointCache) Has(endpointKey string) bool

Has returns if the enpoint cache contains a valid entry for the endpoint key provided.



46
47
48
49
// File 'service/internal/endpoint-discovery/cache.go', line 46

func (c *EndpointCache) Has(endpointKey string) bool { _, found := c.Get(endpointKey) return found }