cache

package
v0.0.0-...-6b32d26 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 15, 2021 License: Apache-2.0 Imports: 14 Imported by: 0

Documentation

Overview

Copyright 2021 SANGFOR TECHNOLOGIES

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ClearCache

func ClearCache()

ClearCache exec delete expired key on all cache in list

func ClearToLog

func ClearToLog(topic string, key string) bool

ClearToLog add topic with key to cache

func FlushHostname

func FlushHostname()

FlushHostname flush hostname cache

func ForgetInstance

func ForgetInstance(key string, forget bool)

ForgetInstance set instance key to cache

func GetAgent

func GetAgent(addr string, valFunc func() (interface{}, error)) (*dtstruct.Agent, error)

GetAgent using default expire when get from cache.

func GetAgentWithExpire

func GetAgentWithExpire(expire time.Duration, addr string, valFunc func() (interface{}, error)) (agt *dtstruct.Agent, err error)

GetAgentWithExpire return agent in cache, if not, get from function valFunc() and add to cache.

func GetAnalysis

func GetAnalysis(key string) (dtstruct.AnalysisCode, bool)

GetAnalysis get analysis from cache

func GetCluster

func GetCluster(key string) (string, bool)

GetCluster get cluster from cache for given instance key

func GetGRPC

func GetGRPC(ctx context.Context, target string, opts ...grpc.DialOption) (conn *grpc.ClientConn, err error)

GetGRPC return grpc conn in cache, if not exist, create it with default conn expire time

func GetGRPCWithExpire

func GetGRPCWithExpire(ctx context.Context, expire time.Duration, target string, opts ...grpc.DialOption) (conn *grpc.ClientConn, err error)

GetGRPCWithExpire return grpc conn in cache and reset conn expire time, if not exist, create it with given expire time

func GetGRPCWithFunc

func GetGRPCWithFunc(ctx context.Context, expire time.Duration, target string, blockFunc func(atomC chan struct{}), opts ...grpc.DialOption) (*grpc.ClientConn, error)

GetGRPCWithFunc return grpc conn in cache and reset conn expire time. if get read/write race, using function in param. if not exist in cache, create it with given expire time

func GetHostname

func GetHostname(hostname string, valFunc func() (interface{}, error)) (string, bool)

GetHostname get hostname from cache

func GetIP

func GetIP(hostname string, valFunc func() (interface{}, error)) ([]net.IP, error)

GetIP get ip from cache, if not exist, get new and put it to cache

func GetKV

func GetKV(key string) (interface{}, bool)

func IsExistInstanceForget

func IsExistInstanceForget(key string) bool

IsExistInstanceForget check if instance is in cache

func IsExpire

func IsExpire(agt *dtstruct.Agent) bool

IsExpire true if too long since last health check.

func ItemHostname

func ItemHostname() map[string]cache.Item

ItemHostname get item in cache

func LogReadTopologyInstanceError

func LogReadTopologyInstanceError(instanceKey *dtstruct.InstanceKey, hint string, err error) error

LogReadTopologyInstanceError logs an error, if applicable, for a ReadTopologyInstance operation, providing context and hint as for the source of the error. If there's no hint just provide the original error.

func NewCache

func NewCache(name string, expiration time.Duration, cleanupInterval time.Duration) *dtstruct.Cache

NewCache create a new cache and append to cache list

func SetAnalysis

func SetAnalysis(key string, analysisCode dtstruct.AnalysisCode)

SetAnalysis put instance analysis code to cache

func SetCluster

func SetCluster(key string, clusterName string, expire time.Duration)

SetCluster set key->cluster name to cache

func SetHostname

func SetHostname(hostname string, resolvedHost string, expire time.Duration)

SetHostname put hostname to cache

func SetKV

func SetKV(key string, value bool, expire time.Duration)

func SetOperationKey

func SetOperationKey(key string, value bool, expire time.Duration) error

func ShowCacheHit

func ShowCacheHit() map[string]float64

ShowCacheHit show all cache hit rate

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL