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

Caching #167

Closed
taf2 opened this issue Jul 1, 2015 · 6 comments
Closed

Caching #167

taf2 opened this issue Jul 1, 2015 · 6 comments

Comments

@taf2
Copy link

taf2 commented Jul 1, 2015

Is it possible to cache requests to get references to accounts when the only thing that will be done is get a list of calls or lookup a call or text....

@philnash
Copy link
Contributor

philnash commented Jul 1, 2015

The thing here is that the status of a call or text can change when you look it up. A call, for example, could have a different status each time you request it during the space of time you may be interested in it. Similarly, lists of calls and texts are changing all the time as more come in.

It's probably better to cache the list or the call or text on your end to deal with your use case.

@taf2
Copy link
Author

taf2 commented Jul 1, 2015

Sorry I wrote this from a mobile phone let me provide more context. The ruby API doesn't make it easy to access a call without first accessing an account. The status of an account doesn't change very often.

Assuming I have the master account sid and token in variables "@sid" and "@sec"

client = Twilio::REST::Client.new @sid, @sec

@call = client.accounts.get(params[:AccountSid]).calls.get(params[:CallSid])

The downside here is I had to fetch the sub account adding an extra request to get the call... I am wondering if maybe there is a better pattern to given the client has master key/sec to fetch calls within a sub account via the ruby interface... From the REST api directly this is easily over come...

@philnash
Copy link
Contributor

philnash commented Jul 1, 2015

The call to client.accounts.get(ACCOUNT_SID) doesn't actually make an HTTP request. It does create an object of the type Twilio::REST::Account passing it the path and the client which it can use to make calls, but it does not make any requests.

In fact, the call to client.accounts.get(params[:AccountSid]).calls.get(params[:CallSid]) makes no requests whatsoever. It will only request the call details lazily, when you make a call for an attribute of the call. Check out this terminal session I tested this with earlier. I added a line locally to the Twilio::REST::BaseClient to puts the method and path when an HTTP request was made. As you can see, after getting both the sub account and the message objects, the single API call is only made when calling for the message's body.

api-requests

Are you seeing different results in your testing?

@philnash
Copy link
Contributor

philnash commented Jul 6, 2015

Hey @taf2, did you find that your client was acting differently or do you think this level of caching is ok? Thanks

@taf2
Copy link
Author

taf2 commented Jul 6, 2015

@philnash looks like it is all okay. I had to modify my usage slightly and now it is all good.

@philnash
Copy link
Contributor

philnash commented Jul 6, 2015

Awesome, just wanted to make sure. Give us a shout on here or on email if you have any other ideas or need pointing in the right direction. Cheers!

@philnash philnash closed this as completed Jul 6, 2015
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

No branches or pull requests

2 participants