Skip to content

Cache in Roomful

Stanislav Osipov edited this page Jun 11, 2024 · 6 revisions

Roomful contains several collections (caches) for different purposes. This article will keep track of those caches as well as a description of purpose, implementation, and API when applicable.

Users Cache

User cache is implemented under the IUsersService service. The cache contains IUserTemplateSimple objects stored in the map using user id as the key.

Purpose:

  • Minimize the amount of requests sent to the server side.

Add:

  • When user info is requested via service API, it will be stored in the service cache. External users can also add to users' cache using IUsersServiceInternal.CacheUser(UserTemplateSimple userTemplate) method.

Clear:

  • The cache is only cleared during the Logout or Network Switch.

Users 2D Avatars & Room Icons Cache

Implemented under the IUsersService and IRoomService services respectively. The cache contains Texture2D objects stored in the map using object id as the key. The Resources cache can not applied here, since we are using the new server API that gives us avatar texture without representing it as the Roomful Resource.

Purpose:

  • Minimize the amount of requests sent to the server side.
  • Speed up textures loading.
  • Force other implementations to reuse already loaded textures, and prevent accidental downloading of the same texture a few times to reduce memory footprint.

Add:

  • Every time an object is requested - it will be added to the cache.

Clear:

  • The cache is only cleared during the Logout or Network Switch.

Room Assets Cache

Implemented inside the IRoomService, based on RequiredAssetsList. Currently hardcoded to save 2 rooms.

Purpose:

  • Significantly speed up room loading if the new room contains the same assets as the room we are currently in.
  • Save entire room assets to enable us to go back to the room almost instantly.

Add:

  • When the room is loaded all the room assets are stored in the cache and located on the Room scene.

Clear:

  • Based on a number of rooms configured to save, unmatched assets will be unloaded.

Textures Cache

See cache implementation inside Textures.cs.

  • The main entry point is void GetThumbnail(IResource res, ThumbnailSize size, Action<Texture2D> callback)
  • We only keep the biggest requested size in the cache using the ContentId as the key.
  • If the IResource has an external image download URL ThumbnailWebURL then size is ignored.
  • If cache already contains a bigger texture size than requested, it will return a bigger size.
  • If a bigger texture size is added to the cache, the smaller texture size will be removed and OnResourceImageUpdated event is triggered, prompting all Texture users to update the used texture to the new one.

Add:

  • Once a new Resource Thumbnail is requested it will be stored in the cache.
  • It's also possible to forcefully assign the thumbnails to the content id.

Clear:

  • Right now only Resources with the tag Room is destroyed when the room is unloaded.
Clone this wiki locally