Skip to content

Conversation

@poppoerika
Copy link
Contributor

Closes #4

Copy link
Contributor

@gautamomento gautamomento left a 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.


class Cache:
def __init__(self, auth_token, cache_name, endpoint, default_ttlSeconds):
"""Inits Cache to perform gets and sets.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Inititalizes

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.
Copy link
Contributor

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.

Args:
auth_token: Momento JWT token.
cahce_name: String of cache name to perform gets and sets.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
cahce_name: String of cache name to perform gets and sets.
cache_name: Name of the cache

self._secure_channel.close()

def set(self, key, value, ttl_seconds=None):
"""Set key/value pair in the cache.
Copy link
Contributor

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

CacheSetResponse
Raises:
Exception to notify either sdk, grpc, or operation error.
Copy link
Contributor

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."""
Copy link
Contributor

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."""
Copy link
Contributor

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.
Copy link
Contributor

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.
Copy link
Contributor

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

return cache._connect()

def list_caches(self, next_token=None):
"""Lists ll caches.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Probably ll -> all

"""Lists ll caches.
Args:
next_token: Token to continue paginating through the list. It's ised to hnadle large paginated lists.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some typos here too.

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.
Copy link
Contributor

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.

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.
Copy link
Contributor

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.

Copy link
Contributor Author

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:
Copy link
Contributor

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:
Copy link
Contributor

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."""
Copy link
Contributor

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.

CreateCacheResponse
Raises:
Exception to notify either sdk, grpc, or operation error.
Copy link
Contributor

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.

Copy link
Contributor

@gautamomento gautamomento left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM.

@poppoerika poppoerika merged commit e053811 into main Jan 13, 2022
@poppoerika poppoerika deleted the chore/addMethodDoc branch January 13, 2022 18:14
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.

Add Methods Documentation

3 participants