FAQ
My code :

type CacheChecker interface {
ReloadCache() error
IsCacheValid() bool
}

type appname2IdCache struct {
rwMu sync.RWMutex // guard the follow fields
appname2Id map[string]int32
lastLoadTime int64
cacheExpireTime int64
}

// called by function refreshCacheRoutine
func (cacheMgr *appname2IdCache) IsCacheValid() bool {

if cacheMgr == nil { // here!
cacheMgr become nil, why ????
logex.Debug("cacheMgr is null")
}

        return true
}

func (cacheMgr *appname2IdCache) ReloadCache() error {
appname2Id, err := db.LoadAllAppname2Id()
if err != nil {
return err
}

         // other code

return nil
}

func refreshCacheRoutine(checkers []CacheChecker) {

logex.Debug("CacheChecker' number: %d", len(checkers))
for {
time.Sleep(5 * time.Second)
for _, oneChecker := range checkers {
if oneChecker == nil { // not nil,
because this log doesn't printed
logex.Debug("oneChecker is null")
}

                   if !oneChecker.IsCacheValid() {
  // call IsCacheValid()
oneChecker.ReloadCache()
}
}
}
}

Just as you see, appname2IdCache implements the interface CacheChecker .
why the receiver is nil in the implemented method???

--
You received this message because you are subscribed to the Google Groups "golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

Search Discussions

  • Matthew Kane at Sep 5, 2013 at 2:38 pm
    Can you show a call to refreshCacheRoutine?
    On Thu, Sep 5, 2013 at 5:04 AM, yuanjun Li wrote:
    My code :

    type CacheChecker interface {
    ReloadCache() error
    IsCacheValid() bool
    }

    type appname2IdCache struct {
    rwMu sync.RWMutex // guard the follow fields
    appname2Id map[string]int32
    lastLoadTime int64
    cacheExpireTime int64
    }

    // called by function refreshCacheRoutine
    func (cacheMgr *appname2IdCache) IsCacheValid() bool {

    if cacheMgr == nil { // here!
    cacheMgr become nil, why ????
    logex.Debug("cacheMgr is null")
    }

    return true
    }

    func (cacheMgr *appname2IdCache) ReloadCache() error {
    appname2Id, err := db.LoadAllAppname2Id()
    if err != nil {
    return err
    }

    // other code

    return nil
    }

    func refreshCacheRoutine(checkers []CacheChecker) {

    logex.Debug("CacheChecker' number: %d", len(checkers))
    for {
    time.Sleep(5 * time.Second)
    for _, oneChecker := range checkers {
    if oneChecker == nil { // not nil,
    because this log doesn't printed
    logex.Debug("oneChecker is null")
    }

    if !oneChecker.IsCacheValid() {
    // call IsCacheValid()
    oneChecker.ReloadCache()
    }
    }
    }
    }

    Just as you see, appname2IdCache implements the interface CacheChecker .
    why the receiver is nil in the implemented method???

    --
    You received this message because you are subscribed to the Google Groups
    "golang-nuts" group.
    To unsubscribe from this group and stop receiving emails from it, send an
    email to golang-nuts+unsubscribe@googlegroups.com.
    For more options, visit https://groups.google.com/groups/opt_out.


    --
    matt kane
    twitter: the_real_mkb / nynexrepublic
    http://hydrogenproject.com

    --
    You received this message because you are subscribed to the Google Groups "golang-nuts" group.
    To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscribe@googlegroups.com.
    For more options, visit https://groups.google.com/groups/opt_out.
  • Chris dollin at Sep 5, 2013 at 3:18 pm

    On 5 September 2013 15:38, Matthew Kane wrote:

    Can you show a call to refreshCacheRoutine?
    On Thu, Sep 5, 2013 at 5:04 AM, yuanjun Li wrote:
    My code :

    type CacheChecker interface {
    ReloadCache() error
    IsCacheValid() bool
    }

    type appname2IdCache struct {
    rwMu sync.RWMutex // guard the follow fields
    appname2Id map[string]int32
    lastLoadTime int64
    cacheExpireTime int64
    }

    // called by function refreshCacheRoutine
    func (cacheMgr *appname2IdCache) IsCacheValid() bool {

    if cacheMgr == nil { // here!
    cacheMgr become nil, why ????
    cacheMgr is a pointer-to-appname2ldCache (and is nil).

    logex.Debug("cacheMgr is null")
    }

    return true
    }

    func (cacheMgr *appname2IdCache) ReloadCache() error {
    appname2Id, err := db.LoadAllAppname2Id()
    if err != nil {
    return err
    }

    // other code

    return nil
    }

    func refreshCacheRoutine(checkers []CacheChecker) {

    logex.Debug("CacheChecker' number: %d", len(checkers))
    for {
    time.Sleep(5 * time.Second)
    for _, oneChecker := range checkers {
    if oneChecker == nil { // not nil,
    because this log doesn't printed
    oneChecker is a CacheChecker -- an interface type -- that is
    not nil, ie, has had a value stored in it. The value stored in it
    /may/ be a nil.

    Remember that an interface value has both the actual value
    and a type in it. Putting a nil value into it will leave the interface
    value as nil but the interface concrete type will be whatever the
    static type of the assigned value is and so the interface value
    /is not nil/.
    logex.Debug("oneChecker is null")
    }

    if !oneChecker.IsCacheValid() {
    // call IsCacheValid()
    oneChecker.ReloadCache()
    }
    }
    }
    }

    Just as you see, appname2IdCache implements the interface CacheChecker .
    why the receiver is nil in the implemented method???
    Chris

    --
    Chris "allusive" Dollin

    --
    You received this message because you are subscribed to the Google Groups "golang-nuts" group.
    To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscribe@googlegroups.com.
    For more options, visit https://groups.google.com/groups/opt_out.
  • Jeremy Wall at Sep 5, 2013 at 3:15 pm
    This is just a guess since you don't show how you call refreshCacheRoutine
    but the zero value of a pointer type is nil. Depending on how you create
    the checkers slice before you call refreshCacheRoutine It's perfectly
    possible to have nil values in that slice.

    On Thu, Sep 5, 2013 at 4:04 AM, yuanjun Li wrote:

    My code :

    type CacheChecker interface {
    ReloadCache() error
    IsCacheValid() bool
    }

    type appname2IdCache struct {
    rwMu sync.RWMutex // guard the follow fields
    appname2Id map[string]int32
    lastLoadTime int64
    cacheExpireTime int64
    }

    // called by function refreshCacheRoutine
    func (cacheMgr *appname2IdCache) IsCacheValid() bool {

    if cacheMgr == nil { // here!
    cacheMgr become nil, why ????
    logex.Debug("cacheMgr is null")
    }

    return true
    }

    func (cacheMgr *appname2IdCache) ReloadCache() error {
    appname2Id, err := db.LoadAllAppname2Id()
    if err != nil {
    return err
    }

    // other code

    return nil
    }

    func refreshCacheRoutine(checkers []CacheChecker) {

    logex.Debug("CacheChecker' number: %d", len(checkers))
    for {
    time.Sleep(5 * time.Second)
    for _, oneChecker := range checkers {
    if oneChecker == nil { // not
    nil, because this log doesn't printed
    logex.Debug("oneChecker is null")
    }

    if !oneChecker.IsCacheValid() {
    // call IsCacheValid()
    oneChecker.ReloadCache()
    }
    }
    }
    }

    Just as you see, appname2IdCache implements the interface CacheChecker .
    why the receiver is nil in the implemented method???

    --
    You received this message because you are subscribed to the Google Groups
    "golang-nuts" group.
    To unsubscribe from this group and stop receiving emails from it, send an
    email to golang-nuts+unsubscribe@googlegroups.com.
    For more options, visit https://groups.google.com/groups/opt_out.
    --
    You received this message because you are subscribed to the Google Groups "golang-nuts" group.
    To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscribe@googlegroups.com.
    For more options, visit https://groups.google.com/groups/opt_out.

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
groupgolang-nuts @
categoriesgo
postedSep 5, '13 at 2:31p
activeSep 5, '13 at 3:18p
posts4
users4
websitegolang.org

People

Translate

site design / logo © 2021 Grokbase