-
Notifications
You must be signed in to change notification settings - Fork 7
chore: add method documentation #15
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
Conversation
gautamomento
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you for doing this.
I have added some comments.
src/momento/cache.py
Outdated
|
|
||
| class Cache: | ||
| def __init__(self, auth_token, cache_name, endpoint, default_ttlSeconds): | ||
| """Inits Cache to perform gets and sets. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Inititalizes
src/momento/cache.py
Outdated
| auth_token: Momento JWT token. | ||
| cahce_name: String of cache name to perform gets and sets. | ||
| end_point: String of endpoint to reach Momento Cache | ||
| default_ttlSeconds: The default time to live of object inside of cache in seconds. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Time (in seconds) for which an item will be stored in the cache.
src/momento/cache.py
Outdated
| Args: | ||
| auth_token: Momento JWT token. | ||
| cahce_name: String of cache name to perform gets and sets. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| cahce_name: String of cache name to perform gets and sets. | |
| cache_name: Name of the cache |
src/momento/cache.py
Outdated
| self._secure_channel.close() | ||
|
|
||
| def set(self, key, value, ttl_seconds=None): | ||
| """Set key/value pair in the cache. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Stores an item in cache
src/momento/cache.py
Outdated
| CacheSetResponse | ||
| Raises: | ||
| Exception to notify either sdk, grpc, or operation error. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's try to be specific -
e.g.
Raises:
CacheNotFound - if an attempt is made to store an item in a cache that doesn't exist
PermissionDenied - if the provided Momento Auth Token is invalid to perform the requested operation
InternalServerError - if server encountered an unknown error while trying to store the item
You will have to look at the exact error names in the errors.py file.
|
|
||
|
|
||
| def str_utf8(self): | ||
| """Decodes string value got from cache to a utf-8 string.""" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should probably say:
Returns value stored in cache as utf-8 string if there was Hit. Returns None otherwise.
| return None | ||
|
|
||
| def bytes(self): | ||
| """Returns byte value got from cache.""" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same as above.
| """Inits ListCacheResponse to handle list cache response. | ||
| Args: | ||
| gprc_list_cache_response: Response returned from list operation. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
See my note about mentioning protobuf from Scs.
|
|
||
| class CacheInfo: | ||
| def __init__(self, grpc_listed_caches): | ||
| """Inits CacheInfo to handle caches returned from list cache operation. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is information about a single cache. Sorry about bad naming here. The variable in init should be grpc_listed_cache. If you are okay with it, do you mind updating the variable name?
You probably have to update this entire object to say cache and not caches
src/momento/momento.py
Outdated
| return cache._connect() | ||
|
|
||
| def list_caches(self, next_token=None): | ||
| """Lists ll caches. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Probably ll -> all
src/momento/momento.py
Outdated
| """Lists ll caches. | ||
| Args: | ||
| next_token: Token to continue paginating through the list. It's ised to hnadle large paginated lists. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Some typos here too.
src/momento/cache.py
Outdated
| ClientSdkError: For all errors raised by the client. Indicates that the request failed on the SDK. | ||
| The request either did not make it to the service or if it did the response from the service could not be parsed successfully. | ||
| InternalServerError: If server encountered an unknown error while trying to store the item. | ||
| SdkError: Base exception for all errors raised by Sdk. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This shouldn't be added here. It is the base error and is never thrown. Comments apply to all methods with raise.
src/momento/cache.py
Outdated
| CacheValueError: If service validation fails for provided values. | ||
| CacheNotFoundError: If an attempt is made to store an item in a cache that doesn't exist. | ||
| PermissionError: If the provided Momento Auth Token is invalid to perform the requested operation. | ||
| ClientSdkError: For all errors raised by the client. Indicates that the request failed on the SDK. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you do a quick code check and see if this operation throws ClientSdkError? Comments apply to all methods with raise.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@gautamomento - Checked and for the methods in cache.py do not throw the ClientSdkError; however some methods in momento.py throws the ClientSdkError when anything other than string is passed as an argument. Updated those Raises section accordingly.
| grpc_set_response: Protobuf based response returned by Scs. | ||
| value (string or bytes): The value to be used to store item in the cache | ||
| Raises: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I doubt if all these errors will be thrown. Can you verify? All I think will come on initialize is InternalServerError from call to error_converter.convert_ecache_result
| Args: | ||
| grpc_get_response: Protobuf based response returned by Scs. | ||
| Raises: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ditto: please verify if these errors will ever come from this method.
| self._name = grpc_listed_cache.cache_name | ||
|
|
||
| def name(self): | ||
| """Returns all caches' names.""" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just this cache's name. This is for a single cache.
src/momento/momento.py
Outdated
| CreateCacheResponse | ||
| Raises: | ||
| Exception to notify either sdk, grpc, or operation error. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Need to update this file.
gautamomento
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM.
Closes #4