Rather than using *args you can supply a default positional only argument.
def temporary_cache(fn=None, *, ttl=60):
if fn is not None:
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, *, ...
You could potentially use incremental computation (think Excel cells that cache values).
Some details (in F#) here:
The above is ported from the Incremental portion of the Aardvark project:
The documentation is all F# since this model works well in a ...
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 ...
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 ...
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 ...
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 :-)
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 ...
Rename concurrentHashMap to internalCache
Rename concurrentLinkedQueue to trackingQueue
Declare using Queue Interface:
Queue<K> trackingQueue = new ConcurrentLinkedQueue<>();
Your get API implementation is not thread safe as pointed out in one of the comments above.
You can do the getElement implementation as ...
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.
public class LruCacheUnitTest
public void LruCacheTest()
var cache = new LruCache<int, string>(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 ...
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.
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 (...
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 ...
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 (...
The review will be focused on readability and testability.
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.