How to implement a 'Cache then network' strategy using Workbox - service-worker

I'm trying to implemement a 'cache then network' strategy using Workbox.
I've set Workbox to use the staleWhileRevalidate runtimeCaching handler, but I'm not sure how best to update the page once/if the cache us updated from the network.
The docs say:
In addition to updating the appropriate caches, it will also trigger any appropriate plugins defined in the underlying RequestWrapper.
Would that be any use? Are there any examples of this strategy being done with Workbox (which, by the way, is a wonderful tool, so thank you to its maintainers)?

There's an example of using the BroadcastCacheUpdate functionality in a "standalone" fashion at https://workbox-samples.glitch.me/examples/workbox-broadcast-cache-update/
To use it along with staleWhileValidate via WorkboxSW's routing, you could do something like:
workboxSW.router.registerRoute(
new RegExp('/some/path/prefix'),
workboxSW.strategies.staleWhileRevalidate({
cacheName: 'my-cache',
broadcastUpdate: {
channelName: 'my-update-channel'
},
})
);
You can see a complete example in the docs.

Related

How to enable auto answer plugin by attribute

I'm trying to use this documentation in order to build a plugin to auto accept an inbound call. What I also want is the ability to turn auto answer on/off by a certain worker attribute. Here's what I have so far in my init(flex, manager) method :
if(manager.workerClient.attributes.[attribute name].includes('[attribute name')) {
manager.workerClient.on('reservationCreated', reservation => {
if (reservation.task.attributes.autoAnswer === 'true') {
flex.Actions.invokeAction('AcceptTask', {sid: reservation.sid});
flex.Actions.invokeAction('SelectTask', {sid: reservation.sid});
}
});
}
I've read through the documentation on accessing worker attributes and think I'm fine with getting the attribute name. However, I'm unsure of the auto answer portion.
Twilio developer evangelist here.
Your code looks correct, I have a similar example that I've used before here.
After discussing with you in the comments, if you set the plugins url to an empty string or null, then Flex will make an API request to look for plugins that it should load at flex.twilio.com/plugins, which only comprises of plugins that you have deployed. You should either set the url to your local /plugins to load the local version. Or you should deploy your plugin so that it can be loaded from flex.twilio.com/plugins in your environment.

Swagger 2 or 3 for Spring Data Rest

I have a spring boot application using spring data rest. I have a problem in providing a well read API documentation using swagger. I tried spring fox and springdoc, but each has its problems
Spring fox:
I can not change the tag name of a repository, only the description
No support for projections
No support of openAPI3 yet (this is actually not a big problem)
Springdoc (https://springdoc.org/)
I can not change neither the tag name nor the description (#Tag does not work on repos)
No support for projections
The same repo gets 3 tags e.g. books-entity-controller, books-search-controller (with methods of a parent class) and books-property-reference-controller (with unnecessary listing of /{id}/{property} urls)
Any better way? I like spring fox for not providing more than one tag, also the auto generated tag names are better e.g. Books Entity instead of books-entity-controller. But it would be better either to customize it or find a better alternative.
I recommand Spring REST Docs over Swagger. Spring REST Docs is test-driven to guarantee your API documentation is always sync with your API.
Andy's talk explains more why Spring REST Docs is more suitable than Swagger for API documentation.
You can find offical simple guide and more samples.
My Github project uses it. You can clone the repository and have a look at the generated documentation HTML /sga-booking/index.html.
Related Spring REST Docs file are
FltApiDocumentation.java
flts.adoc
BookingApiDocumentation.java
booking.adoc
If you find my Github useful, consider give it a star.
Springdoc
I can not change neither the tag name nor the description (#Tag does not work on repos)
and
The same repo gets 3 tags
You can customize it. Use the following at the controller-class level.
#Tag(name = "Name of the Tag", description = "Description of the tag")
or
#Tags(value = {
// Multiple #Tag annotations separated by comma ,
})
or the following at the method level.
#Operation(tags = {"Tag 1", "Tag 2"})
Remember:
#Tag at a class level will override the operation level tags for the particular class.
A class level tag can have only 1 value.
So if you need a controller to have multiple tags, you should isolate it in a different class that doesn't have the #Tag at the class level.
No support for projections
I have never used projections. I generally use the #JsonIgnore to eliminate the ones not needed, but depends on your use-case.
If you want to hide something from a schema, use can use the below method
#Schema(description = "Example POJO to demonstrate the hidden attribute")
class Example {
...
#Schema(hidden = true) // <--- Will be hidden from the Swagger UI completely
String exampleId;
...
}
Hope that helps. Drop a comment for any clarification.

How can I retrieve deleted objects from Active Directory with Ruby?

From the research I've done, it appears I need to send a special OID with my request (1.2.840.113556.1.4.417) in order to access the Deleted Objects container.
I couldn't find a way to send a specific control with a request using the "net-ldap" gem. Does anyone know if this is possible?
There is another gem, ruby-ldap, which appears to be more flexible and it seems I can send controls with my request (e.g. using the search_ext2() method).
However, no matter what I try, I am not getting back any objects, even though I know they haven't been garbage collected yet.
I'm including the filter "isDeleted=TRUE" with my requests as well.
OK, I finally figured it out. One will need to use the ruby-ldap gem. The reason my controls were not being sent was because the LDAP Protocol Version (LDAP::LDAP_OPT_PROTOCOL_VERSION) had defaulted to v2 and apparently it must be v3.
The following is a snippet that works:
require 'ldap'
conn = LDAP::Conn.new('yourserver.example.com', 389)
conn.set_option(LDAP::LDAP_OPT_PROTOCOL_VERSION, 3)
conn.bind("CN=Administrator,CN=Users,DC=example,DC=com", "sekritpass")
# controlType: 1.2.840.113556.1.4.417 (LDAP_SERVER_SHOW_DELETED_OID)
control = LDAP::Control.new('1.2.840.113556.1.4.417')
conn.search_ext2('CN=Deleted Objects,DC=example,DC=com', LDAP::LDAP_SCOPE_SUBTREE, "(isDeleted=*)", nil, false, [control], nil)
The filter (isDeleted=*) isn't necessarily required, you could also simply use (objectClass=*). You can also use the scope LDAP::LDAP_SCOPE_ONELEVEL if desired.
Have you tried isDeleted=* instead?
https://technet.microsoft.com/en-us/library/cc978013.aspx

Where is 's' object cached when using AppMeasurement in DTM

Omniture's basic page tracking function, s.t(), was not crafted for AJAX implementation. Unlike the onclick s.tl() function which has some gating instructions with s.linkTrackVars and s.linkTrackEvents, the s.t() function just perpetuates every cached property through to the next call and beyond.
I used to be able to use a ClearVars function to empty out all of the s object's attributes, but now that I am using AppMeasurement and letting DTM manage my implementation with the most updated version of that library—which I want to keep doing—I can't call the s object. I get the same "ReferenceError: s is not defined" that another person asked about here!.
I tried following Crayon Violent's instructions within that post, but I can't seem to find where DTM is stashing the cached values in between Adobe calls. This code:
window.s = new AppMeasurement();
lets me change/clear the attributes of s, but it's not the s I'm looking for. When I call the next AJAX s.t() function, all of the cached values are still there.
In my experience working with DTM and AA, there has been no end to bugs and caveats and workarounds with DTM's "native integration" of AA. This is why I have more or less decided that the best thing I can do is to either manage the lib myself or else treat AA as a 3rd party script (100% implement it through rules, just ignore that it's available as a tool).
As mentioned in my answer you linked, that line of code only works to expose the AA object in the window namespace if you are managing the library yourself. When you configure DTM to manage the library, it will instantiate AA object itself, and it will be buried within its own code (Honestly, I don't know why DTM did this, considering AA puts a number of other variables in the global namespace that DTM does nothing about).
AFAIK there is no documented way to reference it, but one thing I have found that seems to work for me - which as a disclaimer to cover my own arse I do NOT officially endorse: use at your own risk - is to use the following to get a reference of it:
var s = _satellite.getToolsByType('sc')[0].getS();
This uses getToolsByType method to get an array of the SiteCatalyst (Adobe Analytics) objects setup as tools in DTM. It does this by looping through _satellite.tools and comparing _satellite.tools[n].settings.engine to what you passed to getToolsByType.
Then I use [0] to get the first one in the array, under the assumption that there's only one configured (most people only do one). Then the getS() object pulls together the s object based on the settings in DTM. So from there, you can do things with it, including making use of s.clearVars()

Is there any way to use the DiskCache plugin to cache specific paths from ImageResizer?

We're trying to use ImageResizer to manage our already enormous collection of stored images, and some of them, like Product Images or Header logos we want cached, and that works beautifully using the DiskCache plugin and is awesome.
But, we have other images, like id photos of children and scans of birth certificates, that we want to use ImageResizer for processing, but don't want to be cached, just in case.
I've already had to write some IPlugin's to access our rather... convoluted existing file structure, can I mark in there that the results are not cache-able? Or is there some ability on the DiskCache config line that I haven't noticed yet to whitelist (or blacklist) paths?
Thanks in advance
EDIT: Code of Pipeline Rewrite event as suggested below:
private void PipelineOnRewrite( IHttpModule sender, HttpContext context, IUrlEventArgs urlEventArgs )
{
if( urlEventArgs.VirtualPath.Contains( VirtualFilesystemPrefix ) )
{
urlEventArgs.QueryString.Add("cache", "no");
}
}
DiskCache does protect cached images via access control, using UrlAuthorization (if you have that IIS module installed, as you should).
That said, you can set &cache=no on any request to prevent disk caching. You can do this automatically, server-side, based on any criteria you want, using the Config.Current.Pipeline.Rewrite event handler.

Resources