diff --git a/database/gdb/gdb.go b/database/gdb/gdb.go index 841ef3a58..b3e355c64 100644 --- a/database/gdb/gdb.go +++ b/database/gdb/gdb.go @@ -266,6 +266,9 @@ var ( // which is a regular field name of table. regularFieldNameRegPattern = `^[\w\.\-]+$` + // internalCache is the memory cache for internal usage. + internalCache = gcache.New() + // allDryRun sets dry-run feature for all database connections. // It is commonly used for command options for convenience. allDryRun = false @@ -441,7 +444,7 @@ func (c *Core) getSqlDb(master bool, schema ...string) (sqlDb *sql.DB, err error node = &n } // Cache the underlying connection pool object by node. - v, _ := gcache.GetOrSetFuncLock(node.String(), func() (interface{}, error) { + v, _ := internalCache.GetOrSetFuncLock(node.String(), func() (interface{}, error) { sqlDb, err = c.DB.Open(node) if err != nil { intlog.Printf("DB open failed: %v, %+v", err, node) diff --git a/database/gdb/gdb_driver_mssql.go b/database/gdb/gdb_driver_mssql.go index 488055ace..36fed24fb 100644 --- a/database/gdb/gdb_driver_mssql.go +++ b/database/gdb/gdb_driver_mssql.go @@ -15,7 +15,6 @@ import ( "database/sql" "errors" "fmt" - "github.com/gogf/gf/os/gcache" "strconv" "strings" @@ -199,7 +198,7 @@ func (d *DriverMssql) TableFields(table string, schema ...string) (fields map[st if len(schema) > 0 && schema[0] != "" { checkSchema = schema[0] } - v, _ := gcache.GetOrSetFunc( + v, _ := internalCache.GetOrSetFunc( fmt.Sprintf(`mssql_table_fields_%s_%s`, table, checkSchema), func() (interface{}, error) { var ( diff --git a/database/gdb/gdb_driver_mysql.go b/database/gdb/gdb_driver_mysql.go index 09050845f..00225bbfd 100644 --- a/database/gdb/gdb_driver_mysql.go +++ b/database/gdb/gdb_driver_mysql.go @@ -11,7 +11,6 @@ import ( "errors" "fmt" "github.com/gogf/gf/internal/intlog" - "github.com/gogf/gf/os/gcache" "github.com/gogf/gf/text/gregex" "github.com/gogf/gf/text/gstr" @@ -103,7 +102,7 @@ func (d *DriverMysql) TableFields(table string, schema ...string) (fields map[st if len(schema) > 0 && schema[0] != "" { checkSchema = schema[0] } - v, _ := gcache.GetOrSetFunc( + v, _ := internalCache.GetOrSetFunc( fmt.Sprintf(`mysql_table_fields_%s_%s`, table, checkSchema), func() (interface{}, error) { var ( diff --git a/database/gdb/gdb_driver_oracle.go b/database/gdb/gdb_driver_oracle.go index 8ed74ad0f..181d25fa8 100644 --- a/database/gdb/gdb_driver_oracle.go +++ b/database/gdb/gdb_driver_oracle.go @@ -16,7 +16,6 @@ import ( "errors" "fmt" "github.com/gogf/gf/internal/intlog" - "github.com/gogf/gf/os/gcache" "github.com/gogf/gf/text/gstr" "reflect" "strconv" @@ -159,7 +158,7 @@ func (d *DriverOracle) TableFields(table string, schema ...string) (fields map[s if len(schema) > 0 && schema[0] != "" { checkSchema = schema[0] } - v, _ := gcache.GetOrSetFunc( + v, _ := internalCache.GetOrSetFunc( fmt.Sprintf(`oracle_table_fields_%s_%s`, table, checkSchema), func() (interface{}, error) { result := (Result)(nil) @@ -196,7 +195,7 @@ FROM USER_TAB_COLUMNS WHERE TABLE_NAME = '%s' ORDER BY COLUMN_ID`, func (d *DriverOracle) getTableUniqueIndex(table string) (fields map[string]map[string]string, err error) { table = strings.ToUpper(table) - v, _ := gcache.GetOrSetFunc( + v, _ := internalCache.GetOrSetFunc( "table_unique_index_"+table, func() (interface{}, error) { res := (Result)(nil) diff --git a/database/gdb/gdb_driver_pgsql.go b/database/gdb/gdb_driver_pgsql.go index 81e8b40f7..67989f393 100644 --- a/database/gdb/gdb_driver_pgsql.go +++ b/database/gdb/gdb_driver_pgsql.go @@ -16,7 +16,6 @@ import ( "errors" "fmt" "github.com/gogf/gf/internal/intlog" - "github.com/gogf/gf/os/gcache" "github.com/gogf/gf/text/gstr" "strings" @@ -108,7 +107,7 @@ func (d *DriverPgsql) TableFields(table string, schema ...string) (fields map[st if len(schema) > 0 && schema[0] != "" { checkSchema = schema[0] } - v, _ := gcache.GetOrSetFunc( + v, _ := internalCache.GetOrSetFunc( fmt.Sprintf(`pgsql_table_fields_%s_%s`, table, checkSchema), func() (interface{}, error) { var ( diff --git a/database/gdb/gdb_driver_sqlite.go b/database/gdb/gdb_driver_sqlite.go index 17b55fb2f..378aaeac9 100644 --- a/database/gdb/gdb_driver_sqlite.go +++ b/database/gdb/gdb_driver_sqlite.go @@ -15,7 +15,6 @@ import ( "errors" "fmt" "github.com/gogf/gf/internal/intlog" - "github.com/gogf/gf/os/gcache" "github.com/gogf/gf/os/gfile" "github.com/gogf/gf/text/gstr" "strings" @@ -99,7 +98,7 @@ func (d *DriverSqlite) TableFields(table string, schema ...string) (fields map[s if len(schema) > 0 && schema[0] != "" { checkSchema = schema[0] } - v, _ := gcache.GetOrSetFunc( + v, _ := internalCache.GetOrSetFunc( fmt.Sprintf(`sqlite_table_fields_%s_%s`, table, checkSchema), func() (interface{}, error) { var ( diff --git a/os/gfile/gfile_cache.go b/os/gfile/gfile_cache.go index 1dba5a994..d09cf99c3 100644 --- a/os/gfile/gfile_cache.go +++ b/os/gfile/gfile_cache.go @@ -21,6 +21,9 @@ const ( var ( // Default expire time for file content caching. cacheExpire = cmdenv.Get("gf.gfile.cache", gDEFAULT_CACHE_EXPIRE).Duration() + + // internalCache is the memory cache for internal usage. + internalCache = gcache.New() ) // GetContents returns string content of given file by from cache. @@ -39,13 +42,13 @@ func GetBytesWithCache(path string, duration ...time.Duration) []byte { if len(duration) > 0 { expire = duration[0] } - r, _ := gcache.GetOrSetFuncLock(key, func() (interface{}, error) { + r, _ := internalCache.GetOrSetFuncLock(key, func() (interface{}, error) { b := GetBytes(path) if b != nil { // Adding this to gfsnotify, // it will clear its cache if there's any changes of the file. _, _ = gfsnotify.Add(path, func(event *gfsnotify.Event) { - gcache.Remove(key) + internalCache.Remove(key) gfsnotify.Exit() }) }