Documentation ¶
Index ¶
- func WFTGetValue(value any) string
- func WFTGetValueFromMap(value any) string
- type Cache
- func (c *Cache) Clean()
- func (c *Cache) Delete(key string)
- func (c *Cache) Exists(key string) bool
- func (c *Cache) FTClean() error
- func (c *Cache) FTInit(maxSize int, maxBytes int, minWordLength int) error
- func (c *Cache) FTInitWithJson(file string, maxSize int, maxBytes int, minWordLength int) error
- func (c *Cache) FTInitWithMap(data map[string]map[string]any, maxSize int, maxBytes int, minWordLength int) error
- func (c *Cache) FTIsInitialized() bool
- func (c *Cache) FTSequenceIndices()
- func (c *Cache) FTSetMaxBytes(maxBytes int) error
- func (c *Cache) FTSetMaxSize(maxSize int) error
- func (c *Cache) FTSetMinWordLength(minWordLength int) error
- func (c *Cache) FTStorage() (map[string]any, error)
- func (c *Cache) FTStorageLength() (int, error)
- func (c *Cache) FTStorageSize() (int, error)
- func (c *Cache) Get(key string) map[string]any
- func (c *Cache) Info() (map[string]any, error)
- func (c *Cache) InfoForTesting() (map[string]any, error)
- func (c *Cache) Keys() []string
- func (c *Cache) Length() int
- func (c *Cache) Search(sp SearchParams) ([]map[string]any, error)
- func (c Cache) SearchOneWord(sp SearchParams) ([]map[string]any, error)
- func (c *Cache) SearchValues(sp SearchParams) ([]map[string]any, error)
- func (c *Cache) SearchWithKey(sp SearchParams) ([]map[string]any, error)
- func (c *Cache) Set(key string, value map[string]any) error
- func (c *Cache) Values() []map[string]any
- func (cache *Cache) WithFT(value string) *WFT
- type FullText
- type SearchParams
- type TempStorage
- type WFT
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func WFTGetValue ¶
func WFTGetValueFromMap ¶
WFTGetValueFromMap is a function that gets the full-text value from a map.
Parameters:
- value: any representing the value to get the full-text value from.
Returns:
- A string representing the full-text value, or an empty string if the value is not a map or does not contain the correct keys.
Types ¶
type Cache ¶
type Cache struct {
// contains filtered or unexported fields
}
Cache is a struct that represents an in-memory cache of key-value pairs. The cache can be used to store arbitrary data, and supports concurrent access through a mutex. Additionally, the cache can be configured to support full-text search using a FullText index. Fields:
- data (map[string]map[string]any): A map that stores the data in the cache. The keys of the map are strings that represent the cache keys, and the values are sub-maps that store the actual data under string keys.
- mutex (*sync.RWMutex): A RWMutex that guards access to the cache data.
- ft (*FullText): A FullText index that can be used for full-text search. If nil, full-text search is disabled.
func InitCache ¶
func InitCache() *Cache
InitCache is a function that initializes a new Cache struct and returns a pointer to it.
Returns:
- A pointer to a new Cache struct.
func (*Cache) Clean ¶
func (c *Cache) Clean()
Clean is a method of the Cache struct that clears the cache contents. If the full-text index is initialized, it is also cleared. This method is thread-safe.
Parameters:
- None
Returns:
- None
func (*Cache) Delete ¶
Delete is a method of the Cache struct that removes a key from the cache. If the full-text index is initialized, it is also removed from there. This method is thread-safe.
Parameters:
- key: A string representing the key to remove from the cache.
Returns:
- None
func (*Cache) Exists ¶
Exists is a method of the Cache struct that checks if a key exists in the cache. This method is thread-safe.
Parameters:
- key: A string representing the key to check for existence in the cache.
Returns:
- A boolean value indicating whether the key exists in the cache or not.
func (*Cache) FTClean ¶
FTClean is a method of the Cache struct that clears the full-text cache contents. If the full-text index is not initialized, this method returns an error. Otherwise, the full-text index storage and indices are cleared, and this method returns nil. This method is thread-safe.
Returns:
- error: An error object. If no error occurs, this will be nil.
func (*Cache) FTInit ¶
Initialize the full-text for the cache This method is thread-safe. If the full-text index is already initialized, an error is returned.
Parameters: - maxSize: the maximum number of words to store in the full-text index. - maxBytes: the maximum size, in bytes, of the full-text index.
Returns: - error: If the full-text is already initialized.
func (*Cache) FTInitWithJson ¶
Initialize the full-text for the cache with a JSON file. This method is thread-safe. If the full-text index is already initialized, an error is returned.
Parameters: - file: the path to the JSON file to initialize the full-text index with. - maxSize: the maximum number of words to store in the full-text index. - maxBytes: the maximum size, in bytes, of the full-text index.
Returns: - error: If the full-text is already initialized.
func (*Cache) FTInitWithMap ¶
func (c *Cache) FTInitWithMap(data map[string]map[string]any, maxSize int, maxBytes int, minWordLength int) error
Initialize the full-text index for the cache with a map. This method is thread-safe. If the full-text index is already initialized, an error is returned.
Parameters: - data: the data to initialize the full-text index with. - maxSize: the maximum number of words to store in the full-text index. - maxBytes: the maximum size, in bytes, of the full-text index.
Returns: - error: If the full-text is already initialized.
func (*Cache) FTIsInitialized ¶
FTIsInitialized is a method of the Cache struct that returns a boolean value indicating whether the full-text index is initialized. If the full-text index is initialized, this method returns true. Otherwise, it returns false. This method is thread-safe.
Parameters:
- None
Returns:
- bool: A boolean value indicating whether the full-text index is initialized. If the full-text index is initialized, this method returns true. Otherwise, it returns false.
func (*Cache) FTSequenceIndices ¶
func (c *Cache) FTSequenceIndices()
When you delete a number of keys from the cache, the index remains the same. Over time, this number will grow to be very large, and will cause the cache to use a lot of memory. This function resets the indices to be sequential, starting from 0. This function is thread-safe.
func (*Cache) FTSetMaxBytes ¶
FTSetMaxBytes is a method of the Cache struct that sets the maximum size of the full-text index in bytes. If the full-text index is not initialized, this method returns an error. If the current size of the full-text index is greater than the new maximum size, this method returns an error. Otherwise, the maximum size of the full-text index is set to the specified value, and this method returns nil. This method is thread-safe.
Parameters:
- maxBytes (int): An integer that represents the new maximum size of the full-text index, in bytes.
Returns:
- error: An error object. If no error occurs, this will be nil.
func (*Cache) FTSetMaxSize ¶
FTSetMaxSize is a method of the Cache struct that sets the maximum number of words in the full-text index. If the full-text index is not initialized, this method returns an error. If the current size of the full-text index is greater than the new maximum size, this method returns an error. Otherwise, the maximum number of words in the full-text index is set to the specified value, and this method returns nil. This method is thread-safe.
Parameters:
- maxSize (int): An integer that represents the new maximum number of words in the full-text index.
Returns:
- error: An error object. If no error occurs, this will be nil.
func (*Cache) FTSetMinWordLength ¶
FTSetMinWordLength is a method of the Cache struct that sets the minimum word length for the full-text search. Parameters:
- minWordLength (int): An integer representing the minimum word length.
Returns:
- error: An error if the full-text search is not initialized or if the new minimum word length is greater than the maximum word length.
func (*Cache) FTStorage ¶
FTStorage is a method of the Cache struct that returns a copy of the full-text index storage map. If the full-text index is not initialized, this method returns an error. Otherwise, a copy of the full-text index storage map is returned, and this method returns nil. This method is thread-safe.
Returns:
- map[string][]int: A copy of the full-text index storage map.
- error: An error object. If no error occurs, this will be nil.
func (*Cache) FTStorageLength ¶
FTStorageLength is a method of the Cache struct that returns the number of words in the full-text index storage. If the full-text index is not initialized, this method returns an error. Otherwise, the number of words in the full-text index storage is returned as an integer, and this method returns nil. This method is thread-safe.
Returns:
- int: An integer that represents the number of words in the full-text index storage.
- error: An error object. If no error occurs, this will be nil.
func (*Cache) FTStorageSize ¶
FTStorageSize is a method of the Cache struct that returns the size of the full-text index storage in bytes. If the full-text index is not initialized, this method returns an error. Otherwise, the size of the full-text index storage is returned as an integer, and this method returns nil. This method is thread-safe.
Returns:
- int: An integer that represents the size of the full-text index storage in bytes.
- error: An error object. If no error occurs, this will be nil.
func (*Cache) Get ¶
Get is a method of the Cache struct that retrieves the value associated with the given key from the cache. This method is thread-safe.
Parameters:
- key: A string representing the key to retrieve the value for.
Returns:
- A map[string]any representing the value associated with the given key in the cache.
func (*Cache) Info ¶
Info is a method of the Cache struct that returns a map with the cache and full-text info. This method is thread-safe. An error is returned if the full-text index is not initialized.
Returns:
- A map[string]any representing the cache and full-text info.
- An error if the full-text index is not initialized.
func (*Cache) InfoForTesting ¶
InfoForTesting is a method of the Cache struct that returns a map with the cache and full-text info for testing purposes. This method is thread-safe. An error is returned if the full-text index is not initialized.
Returns:
- A map[string]any representing the cache and full-text info for testing purposes.
- An error if the full-text index is not initialized.
func (*Cache) Keys ¶
Keys is a method of the Cache struct that returns all the keys in the cache. This function is thread-safe.
Returns:
- A slice of strings containing all the keys in the cache.
func (*Cache) Length ¶
Length is a method of the Cache struct that returns the number of items stored in the cache. This function is thread-safe.
Returns:
- An integer representing the number of items stored in the cache.
func (*Cache) Search ¶
func (c *Cache) Search(sp SearchParams) ([]map[string]any, error)
Search is a method of the Cache struct that searches for a query by splitting the query into separate words and returning the search results. Parameters:
- c (c *Cache): A pointer to the Cache struct
- sp (SearchParams): A SearchParams struct containing the search parameters.
Returns:
- []map[string]any: A slice of maps containing the search results.
- error: An error if the query is invalid or if the smallest words array is not found in the cache.
func (Cache) SearchOneWord ¶
func (c Cache) SearchOneWord(sp SearchParams) ([]map[string]any, error)
SearchOneWord searches for a single word in the FullText struct's data and returns a list of maps containing the search results. Parameters:
- c (c *Cache): A pointer to the Cache struct
- sp (SearchParams): A SearchParams struct containing the search parameters.
Returns:
- []map[string]any: A slice of maps where each map represents a data record that matches the given query. The keys of the map correspond to the column names of the data that were searched and returned in the result.
- error: An error if the query or limit is invalid or if the full-text is not initialized.
func (*Cache) SearchValues ¶
func (c *Cache) SearchValues(sp SearchParams) ([]map[string]any, error)
SearchValues searches for all records containing the given query in the specified schema with a limit of results to return. Parameters:
- c (c *Cache): A pointer to the Cache struct
- sp (SearchParams): A SearchParams struct containing the search parameters.
Returns:
- []map[string]any: A slice of maps where each map represents a data record that matches the given query. The keys of the map correspond to the column names of the data that were searched and returned in the result.
- error: An error if the query or limit is invalid
func (*Cache) SearchWithKey ¶
func (c *Cache) SearchWithKey(sp SearchParams) ([]map[string]any, error)
SearchWithKey searches for all records containing the given query in the specified key column with a limit of results to return. Parameters:
- c (c *Cache): A pointer to the Cache struct
- sp (SearchParams): A SearchParams struct containing the search parameters.
Returns:
- []map[string]any: A slice of maps containing the search results
- error: An error if the key, query or limit is invalid
func (*Cache) Set ¶
Set is a method of the Cache struct that sets a value in the cache for the specified key. This function is thread-safe.
Parameters:
- key: A string representing the key to set the value for.
- value: A map[string]any representing the value to set.
Returns:
- Error
func (*Cache) Values ¶
Values is a method of the Cache struct that gets all the values in the cache. This function is thread-safe.
Returns:
- A slice of map[string]any representing all the values in the cache.
type FullText ¶
type FullText struct {
// contains filtered or unexported fields
}
FullText is a struct that represents a full-text index for a cache of data. The index is used to enable full-text search on the data in the cache.
Fields:
- storage (map[string]any): A map that stores the indices of the entries in the cache that contain each word in the full-text index. The keys of the map are strings that represent the words in the index, and the values are slices of integers that represent the indices of the entries in the cache that contain the word.
- indices (map[int]string): A map that stores the words in the full-text index. The keys of the map are integers that represent the indices of the words in the index, and the values are strings that represent the words.
- index (int): An integer that represents the current index of the full-text index. This is used to assign unique indices to new words as they are added to the index.
- maxSize (int): An integer that represents the maximum number of words that can be stored in the full-text index.
- maxBytes (int): An integer that represents the maximum size of the text that can be stored in the full-text index, in bytes.
- minWordLength (int): An integer that represents the minimum length of a word that can be stored in the full-text index.
type SearchParams ¶
type SearchParams struct { // The search query Query string // The limit of search results to return Limit int // A boolean to indicate whether the search should be strict or not Strict bool // A map containing the schema to search for Schema map[string]bool // Key to search in Key string }
SearchParams is a struct that contains the search parameters for the Cache search methods.
type TempStorage ¶
type TempStorage struct {
// contains filtered or unexported fields
}
NewTempStorage is a function that creates a new TempStorage object for a given FullText object. Parameters:
- ft (*FullText): A pointer to the FullText object to create the TempStorage object for.
Returns:
- (*TempStorage): A pointer to the newly created TempStorage object.
func NewTempStorage ¶
func NewTempStorage(ft *FullText) *TempStorage
NewTempStorage is a function that creates a new TempStorage object for a given FullText object. Parameters:
- ft (*FullText): A pointer to the FullText object to create the TempStorage object for.
Returns:
- (*TempStorage): A pointer to the newly created TempStorage object.
Source Files ¶
Directories ¶
Path | Synopsis |
---|---|
cloud
|
|
compression
|
|
examples
|
|
basic
////////////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////////// |
router
/////////////////////////////////////////////////////////////////////////////
|
///////////////////////////////////////////////////////////////////////////// |
examples/router
/////////////////////////////////////////////////////////////////////////////
|
///////////////////////////////////////////////////////////////////////////// |
testing
|
|