-
Notifications
You must be signed in to change notification settings - Fork 45
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
cache get_follow and get_block in stats get prediction (#64)
* cache get_follow and get_block in stats get prediction * create class for cached responses * use buffered channel in stats get prediction queue * move follow and block cache out of stats get prediction * use generic handle func for cached requests
- Loading branch information
Showing
5 changed files
with
157 additions
and
41 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
package proxy | ||
|
||
import "net/http" | ||
|
||
type CachedResponse struct { | ||
response *http.Response | ||
body []byte | ||
} | ||
|
||
type ResponseCache struct { | ||
responses map[string]*CachedResponse | ||
} | ||
|
||
func (c *ResponseCache) ResponseExists(request string) bool { | ||
_, exists := c.responses[request] | ||
return exists | ||
} | ||
|
||
func (c *ResponseCache) GetResponse(request string) (http.Response, []byte) { | ||
response, _ := c.responses[request] | ||
return *response.response, response.body | ||
} | ||
|
||
func (c *ResponseCache) AddResponse(request string, response *http.Response, body []byte) { | ||
c.responses[request] = &CachedResponse{ | ||
response: response, | ||
body: body, | ||
} | ||
} | ||
|
||
func (c *ResponseCache) RemoveResponse(request string) { | ||
delete(c.responses, request) | ||
} |
Oops, something went wrong.