Wire protocol
The following is a description of PaperCache's wire protocol. This is useful when creating a new client. All values are encoded in little-endian. All strings are UTF-8 encoded. Each response is preceeded by a status byte (u8) where 33 is OKAY, and 63 is NOT OKAY.
| Command | Description | Request | OKAY response |
|---|---|---|---|
| PING | Sends a ping request to the server. Useful for health checks. |
|
|
| VERSION | Requests the version number of the cache. |
|
|
| AUTH | Authorizes the client with the server if an auth_token has been configured. |
| |
| GET | Gets the value of the supplied key if it exists, otherwise returns an error value. |
|
|
| SET | Sets a new value with the supplied key. The TTL value is in seconds (a TTL value of 0 indicates no expiry). |
| |
| DEL | Deletes an object if it exists, otherwise returns an error value. |
| |
| HAS | Checks if a value with the supplied key exists. |
|
|
| PEEK | Gets the value of the supplied key if it exists, otherwise returns an error value. Unlike GET, PEEK does not modify the order of the eviction policy stack upon access. |
|
|
| TTL | Sets the TTL of the supplied key if it exists, otherwise returns an error value. The TTL value is in seconds (a TTL value of 0 indicates no expiry). |
| |
| SIZE | Gets the size of the value of the supplied key if it exists, otherwise returns an error value. |
|
|
| WIPE | Deletes all data from the cache. |
| |
| RESIZE | Resizes the cache. |
| |
| POLICY | Sets the cache's eviction policy. |
| |
| STATUS | Gets the cache's status. |
|
|
Errors
The following is a description of PaperCache's error wire protocol. If the initial byte of any response is NOT OKAY (63), the following can be used to parse the subsequent bytes.
| Error type | Description | NOT OKAY response |
|---|---|---|
| INTERNAL | An internal error has occurred. |
|
| MAX_CONNECTIONS_EXCEEDED | The maximum number of concurrent client connections has been exceeded. |
|
| UNAUTHORIZED | The client is not authorized to perform the action. Use the 'auth' command to authorize the client. |
|
| INTERNAL_CACHE_ERROR | An internal error occurred in the cache itself (not the TCP server). |
|
| KEY_NOT_FOUND | The requested key was not found in the cache. |
|
| ZERO_VALUE_SIZE | The provided value has zero size. |
|
| EXCEEDING_VALUE_SIZE | The provided value's size exceeds the size of the cache. |
|
| ZERO_CACHE_SIZE | The provided cache size is zero. |
|
| UNCONFIGURED_POLICY | The provided policy is not configured in the cache. |
|
| INVALID_POLICY | The provided policy is invalid. |
|