You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
@tmatsuo proposed in #110 to cache discovery.build(), however, #294 has stopped using cache outside of the GAE (appengine) environment (see also #299). E.g. the discovery.build() is not cached in the CGE environment. Is it possible to bring the file caching back, or provide some example of file cache (subclass of googleapiclient.discovery_cache.Cache)?
Reacted by Alexandr N. Zamaraev, Michael Safyan, Matija Vižintin, Maximilian Roos, alexferl, Franciszek Żak, Nicolás, Saad Mairaj and Neoma Fong
On Sun, Jan 8, 2017, 2:14 PM Ondrej Medek ***@***.***> wrote:
@tmatsuo <https://github.com/tmatsuo> proposed in #110
<#110> to cache
discovery.build(), however, #294
<#294> has stopped
using cache outside of the GAE (appengine) environment (see also #299
<#299>). E.g.
the discovery.build() is not cached in the CGE environment. Is it
possible to bring the file caching back, or provide some example of file
cache (subclass of googleapiclient.discovery_cache.Cache)?
—
You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub
<#325>, or mute
the thread
<https://github.com/notifications/unsubscribe-auth/AAPUc2WtGDCjrz4H1QhftQxypDuOidnpks5rQV-6gaJpZM4Ld0fj>
.
I created a small workaround by using a in memory cache (see example below). Does anyone know if there should be a regular cache invalidation? Currently the memory cache is cleared on each deployment, I hope that's ok for the time being.
http = ...
service = discovery.build('calendar', 'v3', http=http, cache=MemoryCache())
Reacted by Ondrej Medek, Mitchell Berry, Sanket Sudake, Marcin Owsiany, Ann-Julie Rhéaume, Yixi Zhang, Jason Wolosonovich, Daniel Bishop, Vivek V Krishnan, Dmitriy Geels and 24 more
Reacted by Jason Wolosonovich, Vinícius Dantas and joe
Reacted by Vivek V Krishnan, Vinícius Dantas, Koert van der Veer, joe, Allen Wu, lopezvit, Thomas, Anton Frolov and sebieire
AFAIK the Google production API should not change (the same version of API), so the you do not need to invalidate the cache. However, the discovery_cache/__init__.py defines the limit DISCOVERY_DOC_MAX_AGE as one day.
+1 for a neat, simple MemoryCache. IMO it's good when you have a single, long running process.
If you want to share the cache among processes, (like running scripts by the cron,) you may copy the old good oauth2client locked_file.py and then to plug it somehow with discovery_cache/file_cache.py. Beware, the locked_file.py is considered not 100% save, so you take the risk. (But works well in practice.) By "plugin somehow" I mean either copy & change the discovery_cache/file_cache.py to take your locked_file.py or to trick the Python to think your locked_file.py is from the oauth2client.locked_file package.
@jonparrott what about to change file lock to the multiprocessing.RLock() in the original locked_file.py? Would be it sufficient solution to accept back to the repo?
I'm opting to close this as it's unlikely we will implement it in the future.
These client libraries are officially supported by Google. However, the libraries are considered complete and are in maintenance mode. This means that we will address critical bugs and security issues but will not add any new features.
I don't know if this changed at some point, but I had to import Cache from googleapiclient.discovery_cache.base (presumably googleapiclient.discovery_cache.file_cache also works fine, but inheriting from the Base class is almost certainly the better idea)
Reacted by heisen273, Jakob Salomonsson and anthonymlewis1
I created a small workaround by using a in memory cache (see example below). Does anyone know if there should be a regular cache invalidation? Currently the memory cache is cleared on each deployment, I hope that's ok for the time being.
In case anyone uses the workaround from #325 (comment), beware of the memory leak it can cause in long-running processes. Better to put a bound onto it.
from cachetools import LRUCache
from googleapiclient.discovery_cache.base import Cache as DiscoveryCache
# Set a cache boundary to prevent a memory leak
_discovery_cache: LRUCache = LRUCache(maxsize=100)
class MemoryCache(DiscoveryCache):
def get(self, url: str) -> Optional[str]:
return _discovery_cache.get(url)
def set(self, url: str, content: str) -> None:
_discovery_cache[url] = content
Activity
theacodes commentedon Jan 9, 2017
Schweigi commentedon Jan 22, 2017
Is there a known workaround in the meantime?
Schweigi commentedon Jan 22, 2017
I created a small workaround by using a in memory cache (see example below). Does anyone know if there should be a regular cache invalidation? Currently the memory cache is cleared on each deployment, I hope that's ok for the time being.
In memory cache:
Usage:
xmedeko commentedon Jan 23, 2017
AFAIK the Google production API should not change (the same version of API), so the you do not need to invalidate the cache. However, the
discovery_cache/__init__.pydefines the limitDISCOVERY_DOC_MAX_AGEas one day.+1 for a neat, simple
MemoryCache. IMO it's good when you have a single, long running process.If you want to share the cache among processes, (like running scripts by the cron,) you may copy the old good oauth2client
locked_file.pyand then to plug it somehow withdiscovery_cache/file_cache.py. Beware, thelocked_file.pyis considered not 100% save, so you take the risk. (But works well in practice.) By "plugin somehow" I mean either copy & change thediscovery_cache/file_cache.pyto take yourlocked_file.pyor to trick the Python to think yourlocked_file.pyis from theoauth2client.locked_filepackage.xmedeko commentedon May 17, 2017
@jonparrott what about to change file lock to the
multiprocessing.RLock()in the originallocked_file.py? Would be it sufficient solution to accept back to the repo?theacodes commentedon May 17, 2017
xmedeko commentedon May 17, 2017
You mean a file cache, shared among multiple processes, without any locking? How to prevent data corruption, when 2 process write to the same file?
theacodes commentedon May 17, 2017
3 remaining items
Chronial commentedon Sep 7, 2018
Based on Schweigi's solution, I wrote a simple file based cache (unix-only) to also cache across processes.
busunkim96 commentedon Jun 10, 2019
I'm opting to close this as it's unlikely we will implement it in the future.
Fixed Google caching errors
disable cache_discovery
aawilson commentedon Jun 26, 2020
I don't know if this changed at some point, but I had to import
Cachefromgoogleapiclient.discovery_cache.base(presumablygoogleapiclient.discovery_cache.file_cachealso works fine, but inheriting from the Base class is almost certainly the better idea)fix: Replace default file_cache usage with simple memory cache
fix: Replace default file_cache usage with simple memory cache (#4184)
Kache commentedon Sep 20, 2021
An equivalent & simpler workaround is to set
cache_discovery=False:Since according to the source the "cache" is never reused in the "single, long running process" case.
fix(youtube): cache_discovery issue (googleapis/google-api-python-cli…
neomafo88 commentedon Nov 27, 2022
googleapiclient.discovery_cache.base.Cacheviktoratedgetier commentedon Jun 18, 2026
In case anyone uses the workaround from #325 (comment), beware of the memory leak it can cause in long-running processes. Better to put a bound onto it.
Usage: