Forge Developers | Slack Search | Trello Board Changelog
|
Forge Networking Remastered has been released!!! This is now listed in your Profile!
Go Back

Using The Cache System

The server Cache system (key-value storage) is a way to store transient data on a server session. An example of how the Cache system can be utilized is to have the server keep a running count of kills or player connections. Rather then finding a place in some class to store this information and then make special functions for sending and updating it, you can use the cache system. Then a client at any point can request that data from the server and easily process the response.

Note: In a future release the server wil be able to persist that data to disk for loading later.

The Cache system is found in the BeardedManStudios.Network namespace in a class named "Cache". This is a static class, so you are able to execute methods without an instance.

The following are code snippets on how to use the Cache class on both the client and the server:

Notice how in the server code you are only required to provide a data type, a key and a value. This will create a variable in memory with the key "test" and the value of 9 (in the above example).

Something to be aware of is that each key can only have 1 instance. If you were to assign the key "test" to something else at another point in time, it will be replaced with that new value. So any client that requests the data will get the latest version of it.

Also, it is worth noting that only the server can assign key-value pairs. However both server and clients can perform Get commands.

Title

Body

Title

Body


Input:

Title

Body


Input: