Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in
Toggle navigation
B
beego
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Commits
Issue Boards
Open sidebar
go
beego
Commits
6f3a759b
Commit
6f3a759b
authored
Jan 05, 2014
by
astaxie
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
gmfim add lock. fix #445
parent
338124e3
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
7 additions
and
5 deletions
+7
-5
memzipfile.go
memzipfile.go
+7
-5
No files found.
memzipfile.go
View file @
6f3a759b
...
...
@@ -5,16 +5,17 @@ import (
"compress/flate"
"compress/gzip"
"errors"
//"fmt"
"io"
"io/ioutil"
"net/http"
"os"
"strings"
"sync"
"time"
)
var
gmfim
map
[
string
]
*
MemFileInfo
=
make
(
map
[
string
]
*
MemFileInfo
)
var
lock
sync
.
RWMutex
// OpenMemZipFile returns MemFile object with a compressed static file.
// it's used for serve static file if gzip enable.
...
...
@@ -32,12 +33,12 @@ func OpenMemZipFile(path string, zip string) (*MemFile, error) {
modtime
:=
osfileinfo
.
ModTime
()
fileSize
:=
osfileinfo
.
Size
()
lock
.
RLock
()
cfi
,
ok
:=
gmfim
[
zip
+
":"
+
path
]
lock
.
RUnlock
()
if
ok
&&
cfi
.
ModTime
()
==
modtime
&&
cfi
.
fileSize
==
fileSize
{
//fmt.Printf("read %s file %s from cache\n", zip, path)
}
else
{
//fmt.Printf("NOT read %s file %s from cache\n", zip, path)
var
content
[]
byte
if
zip
==
"gzip"
{
//将文件内容压缩到zipbuf中
...
...
@@ -81,8 +82,9 @@ func OpenMemZipFile(path string, zip string) (*MemFile, error) {
}
cfi
=
&
MemFileInfo
{
osfileinfo
,
modtime
,
content
,
int64
(
len
(
content
)),
fileSize
}
lock
.
Lock
()
defer
lock
.
Unlock
()
gmfim
[
zip
+
":"
+
path
]
=
cfi
//fmt.Printf("%s file %s to %d, cache it\n", zip, path, len(content))
}
return
&
MemFile
{
fi
:
cfi
,
offset
:
0
},
nil
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment