Documentation ¶
Overview ¶
Copyright 2023 The acquirecloud Authors
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.
Copyright 2023 The acquirecloud Authors ¶
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.
Package lru contains the container with limited size capacity and LRU (Least Recently Used) pull out discipline. The continer uses golang generics, so the container can be instantiated for differenty key and value types.
Copyright 2023 The acquirecloud Authors ¶
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.
Copyright 2023 The acquirecloud Authors ¶
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 ¶
This section is empty.
Types ¶
type Cache ¶
type Cache[K comparable, V any] struct { *ECache[K, K, V] }
Cache implements container with limited size capacity and LRU (Least Recently Used) pull out discipline. The elements can be created automatically if they are not found in the pool via the createNewF function call, which is provided via the Cache creation (see NewCache)
func NewCache ¶
func NewCache[K comparable, V any](maxSize int, createNewF CreatePoolElemF[K, V], onDeleteF OnDeleteElemF[K, V]) (*Cache[K, V], error)
NewCache creates new pool object. It expects the maximum pull size (maxSize) and the create new element function in the parameters
type CacheItem ¶
CacheItem - interface for ExpirableItem that needs to be implemented in order to work with ExpirableCache cache
type CreatePoolElemF ¶
CreatePoolElemF function type for creating new pool elements
type ECache ¶
type ECache[PK any, K comparable, V any] struct { // contains filtered or unexported fields }
ECache implements container with limited size capacity and LRU (Least Recently Used) pull out discipline. The elements can be created automatically if they are not found in the pool via the createNewF function call, which is provided via the Cache creation (see NewECache). ECache allows to operate with not comparable type as a primary key. For mapping the type to comparable on MapToInnerKeyF[] should be specified
func NewECache ¶
func NewECache[PK any, K comparable, V any](maxSize int, toComparableF MapToInnerKeyF[PK, K], createNewF CreatePoolElemF[PK, V], onDeleteF OnDeleteElemF[PK, V]) (*ECache[PK, K, V], error)
NewECache creates new pool object. It expects the maximum pull size (maxSize) and the create new element function in the parameters
func (*ECache[PK, K, V]) Clear ¶
Clear cleans up the cache removing all elements. The function will return number of the elements deleted
func (*ECache[PK, K, V]) GetOrCreate ¶
GetOrCreate returns an existing pool element or create the new one by its key
type ExpirableCache ¶
type ExpirableCache[K comparable, V CacheItem] struct { *Cache[K, V] }
ExpirableCache - wrapper around cache that checks if value reached expires at timestamp and re-adds it to the cache by calling the createNewF
func NewExpirableCache ¶
func NewExpirableCache[K comparable, V CacheItem](maxSize int, createNewF CreatePoolElemF[K, V], onDeleteF OnDeleteElemF[K, V]) (*ExpirableCache[K, V], error)
func (*ExpirableCache[K, V]) GetOrCreate ¶
func (p *ExpirableCache[K, V]) GetOrCreate(k K) (V, error)
type ExpirableItem ¶
ExpirableItem - a helper struct for expirable cache. Allows to store any value in cache with a expires at timestamp.