Skip to content

Commit

Permalink
cache acls only when enabled
Browse files Browse the repository at this point in the history
  • Loading branch information
abhishek9686 committed Nov 22, 2023
1 parent 8720962 commit 9855cee
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 5 deletions.
15 changes: 11 additions & 4 deletions logic/acls/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"sync"

"github.com/gravitl/netmaker/database"
"github.com/gravitl/netmaker/servercfg"
"golang.org/x/exp/slog"
)

Expand Down Expand Up @@ -128,8 +129,10 @@ func (aclContainer ACLContainer) Get(containerID ContainerID) (ACLContainer, err
func fetchACLContainer(containerID ContainerID) (ACLContainer, error) {
aclMutex.RLock()
defer aclMutex.RUnlock()
if aclContainer, ok := fetchAclContainerFromCache(containerID); ok {
return aclContainer, nil
if servercfg.CacheEnabled() {
if aclContainer, ok := fetchAclContainerFromCache(containerID); ok {
return aclContainer, nil
}
}
aclJson, err := fetchACLContainerJson(ContainerID(containerID))
if err != nil {
Expand All @@ -139,7 +142,9 @@ func fetchACLContainer(containerID ContainerID) (ACLContainer, error) {
if err := json.Unmarshal([]byte(aclJson), &currentNetworkACL); err != nil {
return nil, err
}
storeAclContainerInCache(containerID, currentNetworkACL)
if servercfg.CacheEnabled() {
storeAclContainerInCache(containerID, currentNetworkACL)
}
return currentNetworkACL, nil
}

Expand Down Expand Up @@ -176,7 +181,9 @@ func upsertACLContainer(containerID ContainerID, aclContainer ACLContainer) (ACL
if err != nil {
return aclContainer, err
}
storeAclContainerInCache(containerID, aclContainer)
if servercfg.CacheEnabled() {
storeAclContainerInCache(containerID, aclContainer)
}
return aclContainer, nil
}

Expand Down
5 changes: 4 additions & 1 deletion logic/acls/nodeacls/modify.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package nodeacls
import (
"github.com/gravitl/netmaker/database"
"github.com/gravitl/netmaker/logic/acls"
"github.com/gravitl/netmaker/servercfg"
)

// CreateNodeACL - inserts or updates a node ACL on given network and adds to state
Expand Down Expand Up @@ -87,6 +88,8 @@ func DeleteACLContainer(network NetworkID) error {
if err != nil {
return err
}
acls.DeleteAclFromCache(acls.ContainerID(network))
if servercfg.CacheEnabled() {
acls.DeleteAclFromCache(acls.ContainerID(network))
}
return nil
}

0 comments on commit 9855cee

Please sign in to comment.