67511dee by astaxie

Merge pull request #73 from matrixik/master

Some docs updates
2 parents 34756852 43f588b5
1 ## cache 1 ## cache
2 cache is a golang cache manager. It can use cache for many adapters. The repo is inspired by `database/sql` . 2 cache is a Go cache manager. It can use many cache adapters. The repo is inspired by `database/sql` .
3 3
4 ##How to install 4
5 ## How to install?
5 6
6 go get github.com/astaxie/beego/cache 7 go get github.com/astaxie/beego/cache
7 8
8
9 ##how many adapter support
10 9
11 Now this cache support memory/redis/memcache 10 ## What adapters are supported?
12 11
13 ## how to use it 12 As of now this cache support memory, Memcache and Redis.
14 first you must import it
15 13
16 14
15 ## How to use it?
16
17 First you must import it
18
17 import ( 19 import (
18 "github.com/astaxie/beego/cache" 20 "github.com/astaxie/beego/cache"
19 ) 21 )
20 22
21 then init an Cache(memory adapter) 23 Then init a Cache (example with memory adapter)
22 24
23 bm, err := NewCache("memory", `{"interval":60}`) 25 bm, err := NewCache("memory", `{"interval":60}`)
24 26
25 use it like this: 27 Use it like this:
26 28
27 bm.Put("astaxie", 1, 10) 29 bm.Put("astaxie", 1, 10)
28 bm.Get("astaxie") 30 bm.Get("astaxie")
29 bm.IsExist("astaxie") 31 bm.IsExist("astaxie")
30 bm.Delete("astaxie") 32 bm.Delete("astaxie")
31 33
32 ## memory adapter 34
33 memory adapter config like this: 35 ## Memory adapter
36
37 Configure memory adapter like this:
34 38
35 {"interval":60} 39 {"interval":60}
36 40
37 interval means the gc time. The cache will every interval time to check wheather have item expired. 41 interval means the gc time. The cache will check at each time interval, whether item has expired.
38 42
39 ## memcache adapter
40 memory adapter use the vitess's [memcache](code.google.com/p/vitess/go/memcache) client.
41 43
42 the config like this: 44 ## Memcache adapter
45
46 memory adapter use the vitess's [Memcache](http://code.google.com/p/vitess/go/memcache) client.
47
48 Configure like this:
43 49
44 {"conn":"127.0.0.1:11211"} 50 {"conn":"127.0.0.1:11211"}
45 51
46 52
47 ## redis adapter 53 ## Redis adapter
48 redis adapter use the [redigo](github.com/garyburd/redigo/redis) client. 54
55 Redis adapter use the [redigo](http://github.com/garyburd/redigo/redis) client.
49 56
50 the config like this: 57 Configure like this:
51 58
52 {"conn":":6039"}
...\ No newline at end of file ...\ No newline at end of file
59 {"conn":":6039"}
......
...@@ -28,7 +28,7 @@ func Register(name string, adapter Cache) { ...@@ -28,7 +28,7 @@ func Register(name string, adapter Cache) {
28 adapters[name] = adapter 28 adapters[name] = adapter
29 } 29 }
30 30
31 //config is json {"interval":360} 31 // config need to be correct JSON as string: {"interval":360}
32 func NewCache(adapterName, config string) (Cache, error) { 32 func NewCache(adapterName, config string) (Cache, error) {
33 adapter, ok := adapters[adapterName] 33 adapter, ok := adapters[adapterName]
34 if !ok { 34 if !ok {
......
1 sessionmanager 1 session
2 ============== 2 ==============
3 3
4 sessionmanager is a golang session manager. It can use session for many providers.Just like the `database/sql` and `database/sql/driver`. 4 session is a Go session manager. It can use many session providers. Just like the `database/sql` and `database/sql/driver`.
5 5
6 ##How to install 6 ## How to install?
7 7
8 go get github.com/astaxie/beego/session 8 go get github.com/astaxie/beego/session
9 9
10 10
11 ##how many providers support 11 ## What providers are supported?
12 Now this sessionmanager support memory/file/redis/mysql
13 12
13 As of now this session manager support memory, file, Redis and MySQL.
14 14
15 15
16 ##How do we use it? 16 ## How to use it?
17
18 first you must import it
19 17
18 First you must import it
20 19
21 import ( 20 import (
22 "github.com/astaxie/beego/session" 21 "github.com/astaxie/beego/session"
23 ) 22 )
24 23
25 then in you web app init the globalsession manager 24 Then in you web app init the global session manager
26 25
27 var globalSessions *session.Manager 26 var globalSessions *session.Manager
28 27
29 use memory as providers: 28 * Use **memory** as provider:
30 29
31 func init() { 30 func init() {
32 globalSessions, _ = session.NewManager("memory", "gosessionid", 3600,"") 31 globalSessions, _ = session.NewManager("memory", "gosessionid", 3600,"")
33 go globalSessions.GC() 32 go globalSessions.GC()
34 } 33 }
35 34
36 use mysql as providers,the last param is the DNS, learn more from [mysql](https://github.com/Go-SQL-Driver/MySQL#dsn-data-source-name): 35 * Use **file** as provider, the last param is the path where you want file to be stored:
37 36
38 func init() { 37 func init() {
39 globalSessions, _ = session.NewManager("mysql", "gosessionid", 3600,"username:password@protocol(address)/dbname?param=value") 38 globalSessions, _ = session.NewManager("file", "gosessionid", 3600, "./tmp")
40 go globalSessions.GC() 39 go globalSessions.GC()
41 } 40 }
42
43 use file as providers,the last param is the path where to store the file:
44 41
45 func init() { 42 * Use **Redis** as provider, the last param is the Redis conn address:
46 globalSessions, _ = session.NewManager("file", "gosessionid", 3600,"./tmp")
47 go globalSessions.GC()
48 }
49 43
50 use redis as providers,the last param is the redis's conn address: 44 func init() {
45 globalSessions, _ = session.NewManager("redis", "gosessionid", 3600, "127.0.0.1:6379")
46 go globalSessions.GC()
47 }
48
49 * Use **MySQL** as provider, the last param is the DSN, learn more from [mysql](https://github.com/Go-SQL-Driver/MySQL#dsn-data-source-name):
51 50
52 func init() { 51 func init() {
53 globalSessions, _ = session.NewManager("redis", "gosessionid", 3600,"127.0.0.1:6379") 52 globalSessions, _ = session.NewManager(
54 go globalSessions.GC() 53 "mysql", "gosessionid", 3600, "username:password@protocol(address)/dbname?param=value")
55 } 54 go globalSessions.GC()
55 }
56 56
57 at last in the handlerfunc you can use it like this 57 Finally in the handlerfunc you can use it like this
58 58
59 func login(w http.ResponseWriter, r *http.Request) { 59 func login(w http.ResponseWriter, r *http.Request) {
60 sess := globalSessions.SessionStart(w, r) 60 sess := globalSessions.SessionStart(w, r)
...@@ -70,19 +70,21 @@ at last in the handlerfunc you can use it like this ...@@ -70,19 +70,21 @@ at last in the handlerfunc you can use it like this
70 fmt.Println("password:", r.Form["password"]) 70 fmt.Println("password:", r.Form["password"])
71 } 71 }
72 } 72 }
73
74 73
75 74
76 ##How to write own provider 75 ## How to write own provider?
77 When we develop a web app, maybe you want to write a provider because you must meet the requirements. 76
77 When you develop a web app, maybe you want to write own provider because you must meet the requirements.
78 78
79 Write a provider is so easy. You only define two struct type(Session and Provider),which satisfy the interface definition.Maybe The memory provider is a good example for you. 79 Writing a provider is easy. You only need to define two struct types
80 (Session and Provider), which satisfy the interface definition.
81 Maybe you will find the **memory** provider as good example.
80 82
81 type SessionStore interface { 83 type SessionStore interface {
82 Set(key, value interface{}) error //set session value 84 Set(key, value interface{}) error // set session value
83 Get(key interface{}) interface{} //get session value 85 Get(key interface{}) interface{} // get session value
84 Delete(key interface{}) error //delete session value 86 Delete(key interface{}) error // delete session value
85 SessionID() string //back current sessionID 87 SessionID() string // return current sessionID
86 SessionRelease() // release the resource 88 SessionRelease() // release the resource
87 } 89 }
88 90
...@@ -93,6 +95,7 @@ Write a provider is so easy. You only define two struct type(Session and Provide ...@@ -93,6 +95,7 @@ Write a provider is so easy. You only define two struct type(Session and Provide
93 SessionGC() 95 SessionGC()
94 } 96 }
95 97
96 ##LICENSE
97 98
98 BSD License http://creativecommons.org/licenses/BSD/
...\ No newline at end of file ...\ No newline at end of file
99 ## LICENSE
100
101 BSD License http://creativecommons.org/licenses/BSD/
......
Styling with Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!