Added force parameter.
This commit is contained in:
parent
da652efb28
commit
2c178c85e6
7
cache/cache.go
vendored
7
cache/cache.go
vendored
@ -53,8 +53,9 @@ func (c *Cache) getFilenames(rawurl string) (hash, jsonFilename, dataFilename st
|
|||||||
// GetReader obtains a Reader for the specified rawurl. If a downloader
|
// GetReader obtains a Reader for the specified rawurl. If a downloader
|
||||||
// currently exists for the URL, a live reader is created and connected to it.
|
// currently exists for the URL, a live reader is created and connected to it.
|
||||||
// If the URL exists in the cache, it is read using the standard file API. If
|
// If the URL exists in the cache, it is read using the standard file API. If
|
||||||
// not, a downloader and live reader are created.
|
// not, a downloader and live reader are created. The force parameter can be
|
||||||
func (c *Cache) GetReader(rawurl string) (Reader, error) {
|
// used to force a new download to be created.
|
||||||
|
func (c *Cache) GetReader(rawurl string, force bool) (Reader, error) {
|
||||||
hash, jsonFilename, dataFilename := c.getFilenames(rawurl)
|
hash, jsonFilename, dataFilename := c.getFilenames(rawurl)
|
||||||
c.mutex.Lock()
|
c.mutex.Lock()
|
||||||
defer c.mutex.Unlock()
|
defer c.mutex.Unlock()
|
||||||
@ -65,7 +66,7 @@ func (c *Cache) GetReader(rawurl string) (Reader, error) {
|
|||||||
if !os.IsNotExist(err) {
|
if !os.IsNotExist(err) {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
} else {
|
} else if !force {
|
||||||
r, err := newDiskReader(jsonFilename, dataFilename)
|
r, err := newDiskReader(jsonFilename, dataFilename)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
|
@ -56,7 +56,7 @@ func (s *Server) ServeHTTP(w http.ResponseWriter, req *http.Request) {
|
|||||||
http.Error(w, "method not allowed", http.StatusMethodNotAllowed)
|
http.Error(w, "method not allowed", http.StatusMethodNotAllowed)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
r, err := s.cache.GetReader(rewrite(req.RequestURI))
|
r, err := s.cache.GetReader(rewrite(req.RequestURI), false)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
http.Error(w, err.Error(), http.StatusInternalServerError)
|
http.Error(w, err.Error(), http.StatusInternalServerError)
|
||||||
log.Println("[ERR]", err)
|
log.Println("[ERR]", err)
|
||||||
|
Loading…
Reference in New Issue
Block a user