CacheBox is a lightweight, multi-type key-value database implemented in Java, designed to simplify your data storage and analysis workflow. It integrates file-based persistence, advanced search capabilities, and an interactive CLI for seamless data exploration. Whether you're working on small-scale data storage, prototyping, or educational purposes, CacheBox provides a robust solution for your needs.
- Zero External Dependencies: Built entirely in Java, CacheBox requires no additional libraries.
- File-Based Persistence: Data is automatically saved to disk, ensuring durability across sessions.
- Multi-Type Support: Store and retrieve data in various formats, including String, Integer, Boolean, List, and Null.
- Advanced Search: Perform complex queries with pattern matching, range searches, and type filtering.
- Interactive CLI: A user-friendly command-line interface for managing your data.
- Encryption Support: Secure your data with AES, XOR, or no encryption strategies.
- Sharding and Load Balancing: Distribute data across multiple shards for better performance.
- Real-Time Monitoring: Track performance metrics and visualize data with live monitoring.
- Data Validation: Ensure data integrity with custom validation rules and type constraints.
- Network Interface and Server: Run CacheBox as a server with a custom CBSP protocol for networked access.
To use CacheBox, follow these steps:
-
Clone the repository:
git clone https://github.com/enmanokatana/CacheBoxDb.git
-
Navigate to the project directory:
cd cachebox -
Build the project using Maven:
mvn clean package
-
Navigate to the scripts directory:
cd scripts -
Start the CLI or server mode depending on your use case:
- To start the CLI:
./start-cli
- To start the server:
./start-server
- To start the CLI:
-
Start the CacheBox CLI:
./start-cli
-
Follow the on-screen instructions to interact with the database.
-
Store a value:
db> put string name John -
Retrieve a value:
db> get name -
Search for values:
db> search -pattern "J.*"
-
Enable encryption:
db> encrypt enable
CacheBox also supports a server mode for networked access. Start the server with:
./start-serverThe server listens on port 20029 by default. You can interact with it using the provided client or custom scripts.
CacheBox supports advanced search queries with the following options:
- Pattern Matching: Use regular expressions to search keys or values.
- Range Queries: Filter numeric values within a specified range.
- Type Filtering: Restrict results to specific data types (e.g., String, Integer).
- Staged vs. Committed: Search only staged (uncommitted) or committed data.
db> search -pattern "na.*"
db> search -range 10 50
db> search -type string
db> search -staged
db> search -committedCacheBox supports encryption for data at rest. You can enable encryption, set encryption algorithms (AES, XOR, or no encryption), and manage encryption keys.
db> encrypt enable
db> encrypt set_algorithm AES
db> encrypt set_key my16bytekey
db> encrypt generate_keyCacheBox supports sharding and load balancing across multiple cache boxes. The ShardedCacheBox class manages multiple shards, and the LoadBalancer distributes requests across these shards.
CacheBox provides real-time performance monitoring and snapshot metrics. You can start live monitoring or take a snapshot of the current performance metrics.
db> snapshot_performance
db> live_performance
db> stop_lpCacheBox includes a custom CBSP (CacheBox Serialization Protocol) for communication between the server and clients. The CBSP protocol is designed to be simple and efficient, supporting the following operations:
- PUT: Store a value in the database.
- GET: Retrieve a value by key.
- DELETE: Remove a key-value pair.
- SEARCH: Perform advanced queries.
- PING: Check server availability.
*3
$3
PUT
$4
name
$4
John
+OK
The CacheBox server runs on port 20029 and supports multiple client connections. It uses a thread pool to handle concurrent requests efficiently.
./start-serverYou can interact with the server using a custom client or tools like telnet:
telnet localhost 20029- Application Configuration Storage: Store application settings and configurations.
- Development and Testing: Use CacheBox for quick data storage in development environments.
- Small-Scale Data Storage: Ideal for small-scale data storage needs.
- Prototyping and Proof of Concepts: Quickly prototype ideas without complex setup.
- Educational Purposes: Learn about key-value databases and data persistence.
- Simple Caching Solutions: Use CacheBox as a lightweight caching layer.
- Key Naming: Use consistent naming conventions and avoid special characters.
- Data Types: Use appropriate data types for values and handle null values explicitly.
- Operations: Check value types before operations and handle exceptions appropriately.
- Search Queries: Use patterns, ranges, and type filtering for structured searches.
- Encryption: Use encryption for sensitive data and manage keys securely.
- Sharding: Distribute data across multiple shards for better performance and scalability.
- Monitoring: Regularly monitor performance and take snapshots for analysis.
We welcome contributions to CacheBox! Here are some areas where you can help:
- Implementing Features: Work on upcoming roadmap features.
- Adding Data Types: Extend support for more data types.
- Performance Improvements: Optimize the database for better performance.
- Testing: Add test coverage for existing and new features.
- Documentation: Improve the documentation and examples.
- Bug Fixes: Report and fix bugs in the repository.
CacheBox is licensed under the MIT License. Feel free to use it in your own projects!
-
2.2 (Current)
- Added encryption support with AES, XOR, and no encryption strategies.
- Introduced sharding and load balancing.
- Added real-time performance monitoring and snapshot metrics.
- Enhanced CLI with encryption management and live monitoring.
- Added network interface and CBSP protocol for server mode.
-
1.1
- Added advanced search and query capabilities.
- Pattern matching, range queries, and type filtering.
- Updated CLI to include search options.
-
1.0
- Multi-type support (String, Integer, Boolean, List).
- Enhanced CLI with type commands.
- Improved error handling.
- Type-aware storage format.
-
0.1 (Initial Release)
- Basic CRUD operations.
- String-only support.
- Simple CLI.
- File-based persistence.
For issues, questions, or contributions, please open an issue in the repository.
Made with ☕ by developers, for developers!