Skip to content
This repository has been archived by the owner on Jul 5, 2020. It is now read-only.

Commit

Permalink
conflicts resolved
Browse files Browse the repository at this point in the history
  • Loading branch information
dariodsa committed May 23, 2020
2 parents 8afc3ec + 8fd3b7a commit 24a60c8
Show file tree
Hide file tree
Showing 4 changed files with 84 additions and 14 deletions.
75 changes: 73 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,83 @@

## What is Cachedb
Cachedb is a lightweight and fast, in-memory data store, which can be used as database cache.

## Installation
Make sure `$GOPATH/bin` is added to your path, then run the following commands.
- `$ go get -u github.com/thetinygoat/cachedb`
- `$ cachedb`

The server will be started on `port 9898`.
The server will be started on `http://localhost:9898`.

## API
All the requests are `GET` requests with paramaters passed as query params. Make sure to convert your keys and values to strings.

##### SET
The set API is simple we need to pass **three** things as query paramaters.

- `key` - this is the the identifier for our data.
- `value` - this is the data to be stored in reference to the key.
- `ttl` - this is the time to live in **seconds**, if you want your key to never expire pass ttl as `-1`.

Example:
`http://localhost:9898/set?key=mykey&value=my-data&ttl=120`

##### GET
The get API takes only one argument.

- `key` - this is the the identifier for our data.

Example:
`http://localhost:9898/get?key=mykey`

##### DEL
The del API also takes just one argument. It removes the specified key from the store.

- `key` - this is the the identifier for our data.

Example:
`http://localhost:9898/del?key=mykey`

##### FLUSH
The flush API does not take any argument. It removes all keys from the store.


Example:
`http://localhost:9898/flush`

## Response
The response is returned as `JSON`.

Examples:
- ``
{
"data": "KEY_DOES_NOT_EXIST_ERROR",
"error": true
}
``
- ``
{
"data": "OK",
"error": false
}
``
- ``
{
"data": "this is cached data",
"error": false
}
``

## Response Codes
At present there are **four** types of errors strings.

- `OK` - operations was successful.
- `KEY_DOES_NOT_EXIST_ERROR` - the specifed key does not exists.
- `KEY_EXPIRED_ERROR` - the key is expired and cannot be automatically deleted from the store.
- `MALFORMED_PARAMS` - some required params are not passed or are invalid.

**NOTE:** Keys are only checked for expiration when they are queried, if you are developing make sure to `flush` the store or it might lead to undesireable results.


## Benchmarks
![Alt Text](https://dev-to-uploads.s3.amazonaws.com/i/8staw4cudsyeepg8cj55.png)
Expand All @@ -22,7 +93,7 @@ Cachedb is currently under development, if you want to contribute feel free to o

- [ ] Work on client libraries
- [ ] Work on multilevel caching
- [ ] Documentation
- [x] Documentation
- [x] Benchmarks
- [x] Work on router

Expand Down
11 changes: 11 additions & 0 deletions constants.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package main

// Constants used throughout the project
const (
MalformedParams = "MALFORMED_PARAMS"
KeyDoesNotExist = "KEY_DOES_NOT_EXIST_ERROR"
KeyExpired = "KEY_EXPIRED_ERROR"
OK = "OK"

DefaultPort = "9898"
)
5 changes: 0 additions & 5 deletions router.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,6 @@ import (
)

// constants
const (
MalformedParams = "MALFORMED_PARAMS"

DefaultPort = "9898"
)

// RouterConfig holds router config
type RouterConfig struct {
Expand Down
7 changes: 0 additions & 7 deletions store.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,6 @@ import (
"github.com/google/uuid"
)

// constants
const (
KeyDoesNotExist = "KEY_DOES_NOT_EXIST_ERROR"
KeyExpired = "KEY_EXPIRED_ERROR"
OK = "OK"
)

// CacheObject : holds cache signature
type CacheObject struct {
Data string
Expand Down

0 comments on commit 24a60c8

Please sign in to comment.