Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Proposed API for a generic keyed cache #23

Open
wants to merge 1 commit into
base: development
Choose a base branch
from

Conversation

charmster
Copy link
Contributor

This includes only the proposed API for a keyed cache that caches object which can be identified by keys.

At present the cache will only be used for inodes and the API includes only those operations necessary to implement a cache for inodes, not everything that one might want in a general purpose cache. (It can always be extended later.)

In particular, the cache doesn't include:

  • a notion of locking (except during object initialization and invalidation)
  • a simple way to check to see if an object is in the cache without instantiating it
  • asynchronous flushing of dirty objects

@charmster charmster changed the title Checkin of files that define the API for the keyed cache. Review the proposed API for a keyed cache Aug 18, 2017
@charmster charmster changed the title Review the proposed API for a keyed cache Proposed API for a generic keyed cache Aug 18, 2017
@@ -0,0 +1,41 @@
# swiftclient
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be

# keyedcache

yeah?

//
func NewCache(cntxt *ReqContext,
newObject func(cntxt *ReqContext, cachedObj *CachedObject) (object Object),
cacheSz uint64, objectSz uint64, keySz uint64) (cache Cache)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What are objectSz and keySz? How are they related to Object.SizeOf and Key.SizeOf?

// o Read() -- called to initialize an object when its assigned an identity;
// it can block arbitrarity but cannot call into this instance of the
// cache.
// o Write() -- called to flush the contents of a dirty object; it can
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd prefer this be named, uh, Flush() :-)

// should not call them, instead they should call methods provided by the cache
// to flush or invalidate objects:
//
// o Read() -- called to initialize an object when its assigned an identity;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this a "Load()" method? Wouldn't we need to have a callback mechanism to enable the generic cache to be able to perform the type-specific "load" operation?

// o Hold() -- get an additional hold on the object
// o Release() -- release a hold on the object; once all holds on an object
// are released the object may be invalidated
// o MarkDirty() -- mark a held object dirty; dirty objects are cleaned
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess we'd require a resource be "held" when calling MarkDirty()...
An alternative might be for the call to Release() to pass back an indication of "dirtiness", but this would mean others wouldn't know it was already dirty until potentially log after it was. Plus, the caller to Release() would be required to "buffer" the knowledge of dirtiness until it was ready to Release() it. I'm fine either way though.

// object can be marked dirty or flushed while multiple threads have a hold on
// the object.
//
// A Cache provides the following methods:
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So no "iterate through"?
I could imagine a desire to "flush everything" wanting an iterator.
Indeed, it might be interesting to iterate just over the dirty entries or just over the clean entries...


const (
INVAL_DIRTY InvalFlush = iota
FLUSH_DIRTY InvalFlush = iota
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm going to assume you want INVAL_DIRTY and FLUSH_DIRTY to have the same (zero) value here?
If not, I think you wanted to remove the second "= iota"... thus emulating an "enum" sequence that Go otherwise lacks.

//
// The *ReqContext is passed through without using it, however the cntxt passed
// to newObject() will be the cntxt passed to the call to Lookup() that
// triggered object creation.
Copy link
Collaborator

@edmc-ss edmc-ss Jun 8, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think there are more callbacks (e.g. hash and equals) that might be useful here...

Release(cntxt *ReqContext)
MarkDirty(cntxt *ReqContext)
IsDirty(cntxt *ReqContext) bool
Flush(cntxt *ReqContext) (err error)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, ok, here is the "flush" upcall/callback... now I see...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants