mirror of
https://github.com/foomo/gocontentful.git
synced 2025-10-16 12:25:39 +00:00
feat: cache bypass to get single entry or asset
This commit is contained in:
parent
a2b22f5d94
commit
c5a2757184
10
README.md
10
README.md
@ -326,9 +326,10 @@ Retrieves all Person entries from the client and returnes a map where the key is
|
||||
|
||||
Retrieves Person entries matching the specified query.
|
||||
|
||||
>(cc *ContentfulClient) **GetPersonByID**(id string) (vo *CfPerson, err error)
|
||||
>(cc *ContentfulClient) **GetPersonByID**(id string, forceNoCache ...bool) (vo *CfPerson, err error)
|
||||
|
||||
Retrieves the Person entry with the specified ID.
|
||||
Retrieves the Person entry with the specified ID. The optional _forceNoCache_ parameter, if true,
|
||||
makes the function bypass the existing cache and load a fresh copy of the entry from Contentful.
|
||||
|
||||
---
|
||||
|
||||
@ -425,9 +426,10 @@ Deletes an asset from the client's cache
|
||||
|
||||
Retrieve all assets from a space
|
||||
|
||||
>(cc *ContentfulClient) **GetAssetByID**(id string) (*contentful.Asset, error)
|
||||
>(cc *ContentfulClient) **GetAssetByID**(id string, forceNoCache ...bool) (*contentful.Asset, error)
|
||||
|
||||
Retrieve an asset from a space by its ID
|
||||
Retrieve an asset from a space by its ID. The optional _forceNoCache_ parameter, if true,
|
||||
makes the function bypass the existing cache and load a fresh copy of the asset from Contentful.
|
||||
|
||||
>**NewAssetFromURL**(id string, uploadUrl string, imageFileType string, title string, locale ...string) *contentful.Asset
|
||||
|
||||
|
||||
@ -230,11 +230,11 @@ func (cc *ContentfulClient) GetAllAssets() (map[string]*contentful.Asset, error)
|
||||
return cc.getAllAssets(true)
|
||||
}
|
||||
|
||||
func (cc *ContentfulClient) GetAssetByID(id string) (*contentful.Asset, error) {
|
||||
func (cc *ContentfulClient) GetAssetByID(id string, forceNoCache ...bool) (*contentful.Asset, error) {
|
||||
if cc == nil || cc.Client == nil {
|
||||
return nil, errors.New("GetAssetByID: No client available")
|
||||
}
|
||||
if cc.Cache != nil && cc.Cache.assets != nil {
|
||||
if cc.Cache != nil && cc.Cache.assets != nil && (len(forceNoCache) == 0 || !forceNoCache[0]) {
|
||||
cc.Cache.assetsGcLock.RLock()
|
||||
asset, okAsset := cc.Cache.assets[id]
|
||||
cc.Cache.assetsGcLock.RUnlock()
|
||||
|
||||
@ -62,11 +62,11 @@ func (cc *ContentfulClient) GetFiltered{{ firstCap $contentType.Sys.ID }}(query
|
||||
return {{ $contentType.Sys.ID }}Map, nil
|
||||
}
|
||||
|
||||
func (cc *ContentfulClient) Get{{ firstCap $contentType.Sys.ID }}ByID(id string) (vo *Cf{{ firstCap $contentType.Sys.ID }}, err error) {
|
||||
func (cc *ContentfulClient) Get{{ firstCap $contentType.Sys.ID }}ByID(id string, forceNoCache ...bool) (vo *Cf{{ firstCap $contentType.Sys.ID }}, err error) {
|
||||
if cc == nil || cc.Client == nil {
|
||||
return nil, errors.New("Get{{ firstCap $contentType.Sys.ID }}ByID: No client available")
|
||||
}
|
||||
if cc.Cache != nil {
|
||||
if cc.Cache != nil && (len(forceNoCache) == 0 || !forceNoCache[0]) {
|
||||
cc.Cache.entryMaps.{{ $contentType.Sys.ID }}GcLock.RLock()
|
||||
vo, ok := cc.Cache.entryMaps.{{ $contentType.Sys.ID }}[id]
|
||||
cc.Cache.entryMaps.{{ $contentType.Sys.ID }}GcLock.RUnlock()
|
||||
|
||||
Loading…
Reference in New Issue
Block a user