Skip to content

Caching

Vincent edited this page Jun 14, 2024 · 17 revisions

Caching

To enhance API performance, frequently accessed data is stored using the QueryConfig class within the Ts3ServerQuery. This approach reduces repetitive data fetching, making operations more efficient.

This is achieved simply by utilizing the QueryConfig class along with its getter method within the Ts3ServerQuery class.

By adding Enums with in the addCacheItem Method to the cache list you can exactly choose what type of objects retrieved by the API you want to store.

If enabled the query will collect the specified information when connecting to the Teamspeakserver (selectVirtualServer Method), be aware of this because it could increase the time needed to connect to a server.

Methods that return cached objects are in the Ts3BasicAPI (and consequently in the Ts3SyncAPI), specifically methods with return values starting with "get".

CacheType Enum (List of Enums to choose from):

public enum CacheType {

    CLIENTS, CHANNELS, GROUPS, DATABASE, PERMISSION, QUERY, VIRTUALSERVER;
}

Different types of caching

Status means how likely the cached Data will be up to date. Recommended means there is no disadvantage instead of the normal Method.

Methods are from the Ts3BasicAPI, but also include the Ts3SyncAPI because it is a subclass.

Updated means when the stored data (like a channel or client) is updated by the api itself.

1. CLIENTS

Stores information about every single client and the clientlist.

Methods: getClient(), getClients()

Updated: ClientJoinEvent, ClientLeaveEvent and ClientMoveEvent

2. CHANNELS

Stores information about every single channel and the channellist.

Methods: getChannel(), getChannels()

Updated: ChannelCreateEvent, ChannelDeletedEvent, ChannelEditedEvent and ChannelMovedEvent

Not updated: ChannelDescriptionEditedEvent and ChannelPasswordChangedEvent because it is included in ChannelEditedEvent.

3. GROUPS

Stores information about the servergrouplist and the channelgrouplist.

Methods: getServerGroups(), getChannelGroups()

Updated: This is not updated by the api itself, you can turn it off temporary to get updated information or update it by yourself. (Using the Method Ts3ServerQuery#getCache().updateServerGroupsCache() or Ts3ServerQuery#getCache().updateChannelGroupsCache().)

4. DATABASE

Stores information about the databaseclients and the databaseclientlist.

Methods: getDataBaseClientInfo(), getDatabaseClients()

Updated: ClientJoinEvent, ClientLeaveEvent (only if Client Caching is enabled)

5. PERMISSION

Stores information about the permissionslist like permissionid, permissionname or permissiondescription

Status: Recommended

Methods: getPermissionList()

Updated: This is not updated by the api itself, you can turn it off temporary to get updated information or update it by yourself (definitely not needed).

6. QUERY

Stores information about the Serverquery. (Recommended to use because beside the ChannelID and the Nickname there is no information that needs an update.)

Status: Recommended

Methods: getQueryInfo()

Updated: ClientMoveEvent (when the Query moves) and 'Ts3BasicAPI#updateQueryName()' if the Nickname is updated.

7. VIRTUALSERVER

Stores information about the virtualserver and his properties.

Methods: getServerInfo() and getVirtualServers()

Updated: ServerEditedEvent

Example:

public class Test {
    
    public static void main(String[] args) {
        Ts3ServerQuery query = new Ts3ServerQuery();
        query.getConfig().addCacheItem(CacheType.PERMISSION);
        query.getConfig().addCacheItem(CacheType.CHANNELS);
        query.getConfig().addCacheItem(CacheType.GROUPS);
        query.getConfig().addCacheItem(CacheType.CLIENTS);
        try {
            query.connect("hostname", 10011, "Username", "Passwort", 1, "Ts³-Bot", 1);
        } catch (IOException | QueryLoginException e) {
            e.printStackTrace();
        }
        query.stopQuery();
    }
}

Clone this wiki locally