Hot answers tagged

5

Rather than using *args you can supply a default positional only argument. def temporary_cache(fn=None, *, ttl=60): ... if fn is not None: return decorator(fn) return decorator If you feel following "flat is better than nested" is best, we can use functools.partial to remove the need to define decorator. def temporary_cache(fn=None, *, ...


4

You could potentially use incremental computation (think Excel cells that cache values). Some details (in F#) here: https://fsprojects.github.io/FSharp.Data.Adaptive/ The above is ported from the Incremental portion of the Aardvark project: https://github.com/aardvark-platform/aardvark.base The documentation is all F# since this model works well in a ...


4

There are two aspects to HTTP Strict Transport Security (HSTS): Implementing HSTS on your site. Submitting your already HSTS enabled site to the HSTS preload list. This is where the "list of HSTS sites" are compiled directly into the browser, which avoids the first request ever being over HTTP (where the request is potentially vulnerable to MITM ...


4

https://gtmetrix.com/ notes that redirects are the largest culprit in slowing down my page loads gtmetrix.com's "suggestion" in this regard is arguably "incorrect" (or rather, not nearly as serious as it implies), assuming you are already consistently linking to the canonical URL*1 throughout your site (and you have no other redirects in ...


3

This is a really bad pattern: neither your Student nor your School class should be responsible for retrieving themselves from the DB. Imagine retrieving a list of 100 Students: that would mean 100+ queries to the DB. You can't even apply filters (e.g. get all the Students who go to one School). Your caching mechanism is solving the wrong problem. What you ...


2

I'd look at python decorators as something, that accepts function and returns function, which is usually original function wrapped in another function and some added behaviour. Change signature of your "decorator" functions to match that and you got something like decorators. Don't have much time at the moment to write examples, but you get the idea :-) ...


2

Seems you know that getting them individually is a bad idea but you are stuck with some legacy code. For your new code the biggest issue you will have is this line. if (MemoryCache.Default["school_" + schoolId] != null) { return (School)MemoryCache.Default["school_" + schoolId.ToString()]; } you should retrieve the value and store in a variable. Then ...


2

Advice 1 Rename concurrentHashMap to internalCache Advice 2 Rename concurrentLinkedQueue to trackingQueue Advice 3 Declare using Queue Interface: Queue<K> trackingQueue = new ConcurrentLinkedQueue<>(); Advice 4 Your get API implementation is not thread safe as pointed out in one of the comments above. You can do the getElement implementation as ...


2

List is internally backed by an array, so item-removal won't be efficient. Use LinkedList instead which is a doubly linked list and allows efficient removal. [TestClass] public class LruCacheUnitTest { [TestMethod] public void LruCacheTest() { var cache = new LruCache<int, string>(2); cache.Put(1, "One"); ...


2

I took a look at it and will elaborate on my few findings below. First of all, your default export is wrong, but most likely you knew about it and you have already fixed it in your local version (might be also some pasting issue) - it's a no brainer. SimpleLocalStorageCache vs. CacheSimpleLocalStorageCache. Also I don't think it's necessary to export the ...


2

Few comments from my side: Looks like a code bug: I think you want to use ReentrantLock to manage concurrent operations in multithreaded environment. But in your code I don't see any place where you have made a call to lock (neither lock() nor tryLock(long timeout, TimeUnit unit)). While unlock() is used couple of time, which is of no use in this case. Other ...


2

I like the codestyle! Code organization tips: Its better to move DDLNode into LRU and make it static, because sole purpose of this class is to be used by LRU class. If you are not going to expose DDLNode to outside world, then it make sense to make it also private. Keeping its fields as public is fine here. If you want to expose DDLNode to outside world (...


1

I have some advices for you. Add the static keyword to the DEFAULT_CACHE_SIZE variable (all cap snake case = constant). Use the size of the map instead of using the capacity variable You can use java.util.HashMap#size. In my opinion, it will be less error-prone to do so (If you forget to update it, ect). Avoid using C-style array declaration In the main ...


1

As the "guy" in question, I'm happy to discuss my approach :) feel free also to file issues on GitHub if you have feedback. You are certainly correct that decorating functions as bash-cache does isn't necessary, but the intent is to simplify the development experience - to memoize a function all you have to do is make a call to bc::cache, and bash-cache (...


1

The review will be focused on readability and testability. Naming I read (I think it was in Clean Code) that variables should not have a postfix like Data and Information and instead we should give things a name that they represent. PortfolioData is actually a Portfolio while your current Portfolio is more a PortfolioRepository or PortfolioCollection. ...


Only top voted, non community-wiki answers of a minimum length are eligible