Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add GetAndTouch Method to Client #177

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

ghrushneshr25
Copy link

@ghrushneshr25 ghrushneshr25 commented Jul 21, 2024

This pull request introduces the GetAndTouch method to the Client struct. The GetAndTouch method retrieves a cache item by its key and updates its expiration time, ensuring that the item remains valid in the cache for the specified duration.

Changes:

Added Method: GetAndTouch
This method calls getAndTouchFromAddr to perform the cache retrieval and expiration time update.
If no item is found (i.e., item is nil), it sets the error to ErrCacheMiss.

Added Method: getAndTouchFromAddr
This method constructs and sends the gat command to the cache server, including the expiration time and key.
It handles the server response and updates the item through the provided callback function.

Usage:

Use GetAndTouch to fetch a cache item and update its expiration time.
Pass a negative expiration value to instantly delete the key from the cache after retrieving it. This approach saves two client calls—one for reading and one for deleting.

How to Use:
item, err := client.GetAndTouch("myKey", 3600)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant