The MultiBackend Cache System is designed to facilitate efficient data caching by utilizing multiple caching strategies. This system supports Inmemory, Memcache and Redis implementations, allowing for flexible, scalable caching solutions suitable for a variety of applications.
- Multiple Cache Backends: Supports Inmemory, Memcache and Redis.
- Docker Integration: Easily deployable in a containerized environment with Docker.
- Concurrency Safe: Thread-safe implementations ensuring data integrity.
- Benchmark Tool: Benchmark tool to test the application performance.
- Grafana Monitoring Tool: Interactive and customizable dashboards for real-time data insights.
- Prometheus: Monitering and collecting metrics to provide for Grafana.
- In Memory - By default, 15% of the system memory will be allotted for the in-memory cache, including the tenant partition. In order to store the cache data into a specific tenant, one has to change config IsTenantBased to true and provide tenantNames (max 3). The cache memory will be split to each tenant equally. There will be slight changes in Api Endpoints.
``` multi-backend-cache/ ├── docker-compose.yml ├── dockerFile ├── go.mod ├── go.sum ├── prometheus.yml ├── router.go ├── docs/ │ ├── docs.go │ ├── swagger.json │ └── swagger.yaml ├── Internal/ │ ├── cache/ │ │ ├── inmemory.go │ │ ├── interface.go │ │ ├── memcache.go │ │ ├── mock_cache.go │ │ ├── redis.go │ │ └── tenantCacheManager.go │ ├── config/ │ │ ├── config.go │ │ └── config.yaml │ ├── Handler/ │ │ ├── handler.go │ │ └── middleware.go │ └── metrices/ │ └── prometheus_model_info.go ├── kuber-deployment/ │ ├── go-service-deployment.yaml │ ├── mem-statefulset.yaml │ ├── redis-configmap.yaml │ ├── redis-statefulset.yaml │ ├── twem-config.yaml │ └── twemproxy.yaml ├── packageUtils/Utils/ │ └── utils.go └── test/ ├── inmemory_test.go ├── server_test.go ├── test_mock.go └── test_server_test.go ```
-
Clone the repository: ```sh git clone https://github.com/FalconDinesh/MultiCacheSystem cd multi-backend-cache ```
-
Build the Docker image: ```sh docker build -t multi-backend-cache . ```
-
Start the services using Docker Compose: ```sh docker-compose up ```
The configuration file `config.yaml` is located in the `Internal/config/` directory. It includes settings for the different cache backends and other application configurations.
The application routes and handlers are defined in `router.go` and the `Internal/Handler/` directory. API documentation is available in the `docs/` directory and can be accessed via Swagger UI.
- redis
- memcache
- inmemory
Postman collection is available in the root directory with the following APIs. One can download and import the collection in Postman and test it.
examples:
with Tenant details http://34.234.207.91:8080/cache?system=inmemory&tenantID=tenant1
```json { "key": "exampleKey", "value": "123", "ttl": 100 } ```
GET - http://34.234.207.91:8080/cache/exampleKey?system=inmemory
with Tenant details http://34.234.207.91:8080/cache/tenant1/exampleKey?system=inmemory&tenantID=tenant1
DELETE - http://34.234.207.91:8080/cache/dhoni?system=inmemory
with Tenant details http://34.234.207.91:8080/cache?system=inmemory&tenantID=tenant1
PUT - http://34.234.207.91:8080/cache/clear?system=inmemory
with Tenant details http://34.234.207.91:8080/cache/clear?system=inmemory&tenantID=tenant1
To test the caches, go to test folder.
- To Test all the cache system at one go
go test
- To test only the inmemory cache APIs
go test inmemory_test.go
- To test only the inmemory Tenant cache APIs
go test inmemorytenant_test.go
- To test only the memcache APIs
go test memcache_test.go
- To test only the redis cache APIs
go test redis_test.go
Used to Benchmark the performace of application. It is a separate go application in the directory MultiBackendCacheSystem/benchmark-tool/. Detailed overview on how to use the tool is provided in the README.md file under the benchmark-tool/ directory.
To monitor the performance of our application, follow these steps to integrate Prometheus and Grafana:
- Grafana
- URL
- username - admin
- password - 28Fo%dT9yb=!wp
- Open your Grafana instance in your web browser.
- Navigate to Configuration (the gear icon) > Data Sources.
- Click on Add data source.
- Select Prometheus from the list.
- In the HTTP section, enter your Prometheus server URL.
- Click on Save & Test to ensure the connection is working.
- In Grafana, go to the + icon on the left sidebar and select Import.
- Upload the JSON file provided for the dashboard or paste the JSON content directly. The JSON file is available in the project root directory in the name grafana-dashboard-config.json
- Click Load.
- Select the Prometheus data source that you added in the previous step.
- Click Import to add the dashboard.
- Open the imported dashboard.
- To customize or add new visualizations, click on any panel to edit.
- Use the Run Query button to execute the desired queries and visualize the data.
These steps will enable you to monitor total requests, successful hits, failed hits, overall performance, and throughput of the entire application using Prometheus and Grafana.