jcabi-github icon indicating copy to clipboard operation
jcabi-github copied to clipboard

Caching layer

Open cezarykluczynski opened this issue 10 years ago • 3 comments

I would expect that calling something like:

User privateUser = github.users().get(name);
Smart user = new Smart(privateUser);
user.login();
user.avatarUrl().toString();
user.type();

will call the user resource once, and then extract stored data when login(), avatarUrl(), and type() are called. Seems like this is not the case, and new API request is performed for every method call. Am I missing something here? Is this the intended behaviour?

It seems like the only option to get all the user data in a single request, and single request is the only choice for me, is to get the raw JSON, and then extract everything from it, bypassing ale the nice getters User.Smart have.

cezarykluczynski avatar Aug 22 '15 08:08 cezarykluczynski

@yegor256 please do something about this issue

dmarkov avatar Aug 25 '15 10:08 dmarkov

+100

cvrebert avatar Aug 29 '15 23:08 cvrebert

@cezarykluczynski yes, that's how it is intended to be. The only way to "fix" this is to introduce a new "caching" decorator of Github, which you would use like this:

User privateUser = new CachedGithub(github).users().get(name);
Smart user = new Smart(privateUser);
user.login();
user.avatarUrl().toString();
user.type();

Pay attention to new CachedGithub(github). See how a similar thing is implemented in, say, https://github.com/jcabi/jcabi-s3/tree/master/src/main/java/com/jcabi/s3/cached

yegor256 avatar Sep 13 '15 10:09 yegor256