-
Notifications
You must be signed in to change notification settings - Fork 102
Caching
All SteamObject-type objects returned via the API use a form of caching for their properties. Some are cached permanently (retrieved once, kept until object's deletion), while some are cached for a set amount of time. (But refreshed only on-demand after the cache's expiration)
Some properties aren't likely to change throughout the object's life, like names. Those properties are cached indefinitely, until the object's deletion. (Not on the disk)
Other properties have tuned-caching, based on how likely they are to change. A user's friends list, for example, is cached for 30 minutes, because it's unlikely that it will change in under 30 minutes.
Cache objects are checked every time a property is requested. If they expired, a new request will be made. You can invalidate a property's cache manually, by deleting its key from the associated _cache:
>>> f = me.friends
# a few seconds pass
>>> me.friends
[<SteamUser "Ryan" (9876543210987654321)>, <SteamUser "Tyler" (1234876598762345)>, ...] # immediately
>>> del me._cache['friends']
>>> f = me.friends
# another few seconds pass, since there's no cached response availableSome properties return lists of objects, like friends or games. These lists are big, and requesting data for each and every object could take a long time. That's why they perform precaching.
For example, when friends are requested, steamapi performs the following actions:
- Ask the web API for a list of friends -> Receive a list of IDs.
- Divide the list into large chunks (up to 35 friends each at this time) and ask the web API for details on each chunk.
- Manually initialise & fill each object's cache with the relevant info.
- Return the finalised list.
For a list of about 70 friends (mine), this takes only 2-3 seconds instead of about 50, because only 2 user queries are performed instead of 70.
For cases where pre-caching is not necessary, like traversing a network of friends without resolving their details (only using their unique IDs), it can be disabled:
>>> con = APIConnection() # get the active connection (Singleton)
>>> con.precaching = FalseYou can also disable it on-start:
>>> APIConnection(api_key="ABCDEFGHIJKLMNOPQRSTUVWXYZ", settings={'precaching': False})