question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

put context caching functionality under context.cache

See original GitHub issue

(adapted from https://github.com/Microsoft/botbuilder-js/issues/66#issuecomment-368210787)

Let’s put the context cache functionality under the name context.Cache (.net, where it would presumably be a Dictionary), and context.cache (JS, where it would be a Map):

C#

if (context.Cache.ContainsKey("myKey")) {
    value = context.Cache["myKey"};
    context.Cache.Remove("myKey");
}

JavaScript

if (context.cache.has("mykey")) {
    value = context.cache.get("myKey");
    context.cache.delete("myKey");
}

This strikes a better balance between common naming across SDKs and language-specific idiom.

In the current JS implementation, context just exposes get/has/set - functions, which by themselves don’t telegraph much about their purpose. This puts them behind a meaningful identifier.

Most bot developers will never used the cache directly, and this reduces the surface area of context (the list that pops up under intellisense).

Finally, by exposing the underlying object directly, the technical debt of this feature goes down.

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:11 (10 by maintainers)

github_iconTop GitHub Comments

2reactions
billbacommented, Mar 16, 2018

There were several instances from this week’s hack where people tried to use context.set/.get for the “wrong” thing. The more descriptively we can name this, e.g. context.serviceCache, the more likely it won’t be abused.

I also think we could go further and explore even more verbosity. My favorite method name in the world (doesn’t everyone have a favorite method name?) is React’s dangerouslySetInnerHTML because it’s wildly descriptive: you can set the HTML but you should think twice and probably Google to see what’s so dangerous. So maybe something like context.cacheReallyJustForServices. It sounds like a joke, but if it forces people to look it up then its accomplished its goals.

0reactions
billbacommented, Apr 16, 2018

I don’t understand your comment - this DCR – which was not about state – was adopted in full (we eventually settled on context.service/context.Service).

Read more comments on GitHub >

github_iconTop Results From Across the Web

Context Caching :: Spring Framework
Once the TestContext framework loads an ApplicationContext (or WebApplicationContext ) for a test, that context is cached and reused for all ...
Read more >
Improve Build Times with Context Caching from Spring Test
Understand how the Context Caching mechanism from Spring Test can improve your build time while resuing an already started context.
Read more >
Cache contexts | Cache API
Cache contexts provide a declarative way to create context-dependent variations of something that needs to be cached.
Read more >
Troubleshooting Spring TestContext caching
Spring TestContext Framework caches context based on several keys. How can I log cache keys to ensure that my tests reuse contexts? spring-test....
Read more >
What is the correct way to set cache contexts on custom blocks?
In most cases, you just set the cache context directly on the render array you return in your build() method. I have finally...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found