I developed my own subscription cache manager today (based @diaconutheodor’s sample, ccorcos:subs-cache and kadirahq:subsmanager). I wanted minimal stuff like cache limit and expiration, so it was still harder than the sample.
Basically, the most limiting area is that (like in thoses packages mentionned above) i only have control over the number of subscriptions, but not the size of the subscribed data. When setting up a cache, i would like to be able (ideally) to decide how much RAM i should use on the client’s browser for the cached data, and manage subscriptions accordingly (i.e: deleting the older ones).
I’m still thinking that ideally, the basic developer’s work should’nt be more complicated than something like:
if( Meteor.isClient() ) {
Meteor.setCacheSize( 20 ); // 20MB
}
We could default this to 0, if we want to be careful.
Going in further for better perf tweaking, we could be defining multiples caches for managing different lifetimes with a slightly different API:
// cache for admin stuff, 40MB size, 5min lifetime
var adminCache = new Meteor.Cache(40, { expire: 5 });
var subHandle = adminCache.subscribe(...);
Destroying the adminCache object here would result in a cleaning of the cache and subscriptions (provided they are not also subscribed by other Meteor.Cache objects).
I hear that some of you think that performance optimization should be fine tuning. That’s right, but only at some stage of your project. Let’s no be blind here.
I’ve used Meteor for several projects already, and installing a subcache package took me a few minutes and resulted in a drastic performance improvement for almost all uses case on all my apps.
Meteor already did a great job reducing the client/server communication into a simple pub/sub/templating pattern, so why not go further and also cut the bandwith usage with a simple caching tool?