Gmail API와 연결되는 Django 앱을 만들고 있는데 google-api-python-client 용 문서 인 httplib2 수준에서 요청을 캐싱하려고합니다. https://developers.google.com/api-client-library/python/guide/performanceMemcached가 Gmail API와 작동하지 않음
문제는 호출이 제대로 이루어지고 python이 memcached에 연결할 수 있지만 memcached에서 키를 찾지 못하는 것입니다 (memcached 출력을 올바르게 읽는 경우). 여기
from django.core.cache import cache
flow = flow_from_clientsecrets(CLIENT_SECRET_FILE, scope=OAUTH_SCOPE)
http = httplib2.Http(cache=cache)
credentials = STORAGE.get()
if credentials is None or credentials.invalid:
credentials = run(flow, STORAGE, http=http)
http = credentials.authorize(http)
gmail_client = build('gmail', 'v1', http=http)
batch = BatchHttpRequest()
messages = gmail_client.users().messages().list(userId='me', maxResults=1).execute()
if messages['messages']:
for message in messages['messages']:
batch.add(gmail_client.users().messages().get(userId='me', id=message['id'], format='metadata', fields="payload,threadId,id", metadataHeaders=['subject','date','to','from']), callback=messageCallback)
batch.execute()
을 그리고 memcached를 로그 모양을 : 코드는 다음과 같습니다 무슨 일이 일어나고 있는지
## First time running the http request
<27 new auto-negotiating client connection
27: Client using the ascii protocol
<27 get :1:https://www.googleapis.com/discovery/v1/apis/gmail/v1/rest
>27 END
<27 set :1:https://www.googleapis.com/discovery/v1/apis/gmail/v1/rest 0 300 53713
>27 STORED
<27 get :1:https://www.googleapis.com/gmail/v1/users/me/messages?alt=json&maxResults=1
>27 END
<27 get :1:https://accounts.google.com/o/oauth2/token
>27 END
<27 delete :1:https://accounts.google.com/o/oauth2/token
>27 NOT_FOUND
<27 get :1:https://www.googleapis.com/gmail/v1/users/me/messages?alt=json&maxResults=1
>27 END
<27 delete :1:https://www.googleapis.com/gmail/v1/users/me/messages?alt=json&maxResults=1
>27 NOT_FOUND
<27 get :1:https://www.googleapis.com/batch
>27 END
<27 delete :1:https://www.googleapis.com/batch
>27 NOT_FOUND
<27 quit
<27 connection closed.
## Second time running the http request
<27 new auto-negotiating client connection
27: Client using the ascii protocol
<27 get :1:https://www.googleapis.com/discovery/v1/apis/gmail/v1/rest
>27 sending key :1:https://www.googleapis.com/discovery/v1/apis/gmail/v1/rest
>27 END
<27 get :1:https://www.googleapis.com/gmail/v1/users/me/messages?alt=json&maxResults=1
>27 END
<27 delete :1:https://www.googleapis.com/gmail/v1/users/me/messages?alt=json&maxResults=1
>27 NOT_FOUND
<27 get :1:https://www.googleapis.com/batch
>27 END
<27 delete :1:https://www.googleapis.com/batch
>27 NOT_FOUND
<27 quit
<27 connection closed.
어떤 생각?
이러한 요청을 캐싱하는 요령은 무엇입니까? 매번 최신 결과를 기대해서는 안됩니까? 나는 구글이 캐싱을 막는 헤더를 보내고 있다고 생각한다. –
좋습니다 (GET https://www.googleapis.com/discovery/v1/apis/gmail/v1/rest) 중 하나 이상이 캐시 제어 : 공개, 최대 연령 = 300, 재 검증 필요, 아니요 -transform'을 사용하여 캐시 가능해야합니다. –
@ Alex3917, 코드의 일부분에서 memcache로 캐시하려고하는 것으로 나타 났습니까? Memcache가 캐싱을 전혀하지 않는다고 어떻게 말할 수 있습니까? – Anzel