Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
gosqlite
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
gosqlite
Commits
0c9e9523
Commit
0c9e9523
authored
12 years ago
by
gwenn
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Introduce a structure to cache statements (not used yet).
parent
c4bfbe45
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
62 additions
and
0 deletions
+62
-0
cache.go
cache.go
+62
-0
No files found.
cache.go
0 → 100644
View file @
0c9e9523
// Copyright 2010 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package
sqlite
import
(
"container/list"
"sync"
)
type
Cache
struct
{
m
sync
.
Mutex
l
*
list
.
List
MaxSize
int
// Cache turned off when MaxSize <= 0
}
func
(
c
*
Cache
)
find
(
sql
string
)
*
Stmt
{
if
c
.
MaxSize
<=
0
{
return
nil
}
c
.
m
.
Lock
()
defer
c
.
m
.
Unlock
()
for
e
:=
c
.
l
.
Front
();
e
!=
nil
;
e
=
e
.
Next
()
{
if
s
,
ok
:=
e
.
Value
.
(
*
Stmt
);
ok
{
if
s
.
SQL
()
==
sql
{
c
.
l
.
Remove
(
e
)
return
s
}
}
}
return
nil
}
func
(
c
*
Cache
)
release
(
s
*
Stmt
)
{
if
c
.
MaxSize
<=
0
{
s
.
Finalize
()
return
}
c
.
m
.
Lock
()
defer
c
.
m
.
Unlock
()
c
.
l
.
InsertBefore
(
s
,
c
.
l
.
Front
())
for
c
.
l
.
Len
()
>
c
.
MaxSize
{
v
:=
c
.
l
.
Remove
(
c
.
l
.
Back
())
if
s
,
ok
:=
v
.
(
*
Stmt
);
ok
{
s
.
Finalize
()
}
}
}
func
(
c
*
Cache
)
flush
()
{
c
.
m
.
Lock
()
defer
c
.
m
.
Unlock
()
var
e
,
next
*
list
.
Element
for
e
=
c
.
l
.
Front
();
e
!=
nil
;
e
=
next
{
next
=
e
.
Next
()
v
:=
c
.
l
.
Remove
(
e
)
if
s
,
ok
:=
v
.
(
*
Stmt
);
ok
{
s
.
Finalize
()
}
}
}
This diff is collapsed.
Click to expand it.
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