API Reference
TagCache provides two high-performance APIs: a JSON HTTP API for web applications and a binary TCP protocol for ultra-low latency operations.
HTTP JSON API
The HTTP API runs on port 8080 (configurable) and provides a RESTful interface with JSON payloads.
Base URL
http://localhost:8080/apiAuthentication
All API endpoints require HTTP Basic Authentication:
| |
Content Type
All POST/PUT requests should include:
Content-Type: application/jsonResponse Format
All responses follow this structure:
| |
Error responses:
| |
Cache Operations
Set Key
Set a key-value pair with optional TTL and tags.
| |
Request Body:
| |
Response:
| |
cURL Example:
| |
Get Key
Retrieve a single key.
| |
Response:
| |
cURL Example:
| |
Get Multiple Keys
Retrieve multiple keys in a single request.
| |
Request Body:
| |
Response:
| |
Get by Tag
Retrieve all keys associated with a specific tag.
| |
Response:
| |
cURL Example:
| |
Delete Key
Delete a single key.
| |
Response:
| |
cURL Example:
| |
Delete by Tag
Delete all keys associated with a tag.
| |
Response:
| |
cURL Example:
| |
Atomic Operations
Add (Set if Not Exists)
Set a key only if it doesn’t already exist.
| |
Request Body:
| |
Response:
| |
Increment
Atomically increment a numeric value.
| |
Request Body:
| |
Response:
| |
cURL Example:
| |
Decrement
Atomically decrement a numeric value.
| |
Request Body:
| |
Response:
| |
Information & Monitoring
Check if Key Exists
| |
Response:
| |
Get Key Information
Get metadata about a key without retrieving its value.
| |
Response:
| |
List Tags
Get all tags currently in use.
| |
Response:
| |
Server Statistics
Get comprehensive server statistics.
| |
Response:
| |
Health Check
Simple health check endpoint.
| |
Response:
| |
TCP Protocol
The TCP protocol provides ultra-low latency operations using a binary format. It runs on port 1984 (configurable).
Connection
| |
Protocol Format
All TCP messages follow this binary format:
[Length: 4 bytes][Command: 1 byte][Data: variable]- Length: Total message length (big-endian uint32)
- Command: Operation code (uint8)
- Data: Command-specific payload
Command Codes
| Command | Code | Description |
|---|---|---|
| AUTH | 0x01 | Authenticate |
| SET | 0x02 | Set key-value |
| GET | 0x03 | Get value |
| DELETE | 0x04 | Delete key |
| EXISTS | 0x05 | Check if key exists |
| ADD | 0x06 | Add if not exists |
| INCR | 0x07 | Increment |
| DECR | 0x08 | Decrement |
| STATS | 0x09 | Get statistics |
| PING | 0x0A | Ping server |
Authentication
| |
Set Operation
| |
Get Operation
| |
Client Libraries
Python
| |
JavaScript/Node.js
| |
Go
| |
Error Codes
HTTP Status Codes
200 OK: Success400 Bad Request: Invalid request format401 Unauthorized: Authentication failed404 Not Found: Key not found409 Conflict: Key already exists (for ADD operations)500 Internal Server Error: Server error
TCP Response Codes
0x01: Success0x02: Key not found0x03: Authentication failed0x04: Invalid command0x05: Server error0x06: Key already exists
Performance Considerations
HTTP API
- Use HTTP/1.1 keep-alive for connection reuse
- Batch multiple operations when possible
- Consider TCP protocol for high-frequency operations
TCP Protocol
- Maintain persistent connections
- Use connection pooling for concurrent applications
- Implement proper error handling and reconnection logic
General Tips
- Use appropriate TTL values to prevent memory bloat
- Leverage tags for efficient batch operations
- Monitor cache hit rates and adjust strategies accordingly