forked from mantzas/patron
-
Notifications
You must be signed in to change notification settings - Fork 66
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Cache doc and code improvement (#588)
<!-- Thanks for taking precious time for making a PR. Before creating a pull request, please make sure: - Your PR solves one problem for which an issue exist and a solution has been discussed - You have read the guide for contributing - See https://github.com/beatlabs/patron/blob/master/README.md#how-to-contribute - You signed all your commits (otherwise we won't be able to merge the PR) - See https://github.com/beatlabs/patron/blob/master/SIGNYOURWORK.md - You added unit tests for the new functionality - You mention in the PR description which issue it is addressing, e.g. "Resolves #123" --> ## Which problem is this PR solving? Closes #555 and improves the API of the cache abstractions. This is a BREAKING CHANGE. ## Short description of the changes - Introduced context to the cache methods - Improved Go documentation Co-authored-by: Dionysis Xenos <[email protected]>
- Loading branch information
Showing
13 changed files
with
135 additions
and
138 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,20 +1,26 @@ | ||
// Package cache provide abstractions for concrete cache implementations. | ||
// Package cache provides abstractions to allow the creation of concrete implementations. | ||
package cache | ||
|
||
import ( | ||
"context" | ||
"time" | ||
) | ||
|
||
// Cache interface. | ||
// Cache interface that defines the methods required. | ||
type Cache interface { | ||
Get(key string) (interface{}, bool, error) | ||
Purge() error | ||
Remove(key string) error | ||
Set(key string, value interface{}) error | ||
// Get a value based on a specific key. The call returns whether the key exists or not. | ||
Get(ctx context.Context, key string) (interface{}, bool, error) | ||
// Purge the cache. | ||
Purge(ctx context.Context) error | ||
// Remove the key from the cache. | ||
Remove(ctx context.Context, key string) error | ||
// Set the value for the specified key. | ||
Set(ctx context.Context, key string, value interface{}) error | ||
} | ||
|
||
// TTLCache interface adds support for expiring key-value pairs. | ||
// TTLCache interface adds support for expiring key value pairs. | ||
type TTLCache interface { | ||
Cache | ||
SetTTL(key string, value interface{}, ttl time.Duration) error | ||
// SetTTL sets the value of a specified key with a time to live. | ||
SetTTL(ctx context.Context, key string, value interface{}, ttl time.Duration) error | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.