第一行“如果已经有了 i 就不放了”应该为“如果已经有了 i 就把它取出然后放到队列末尾”。
原文翻译:
Suppose the cache may store no more than k objects. At the beginning of the workflow the cache is empty. When some object is queried we check if it is present in the cache and move it here if it's not. If there are more than k objects in the cache after this, the least recently used one should be removed. In other words, we remove the object that has the smallest time of the last query.
假设缓存中存储的对象不超过 k个。在工作流程开始时,缓存是空的。当某个对象被查询时,我们会检查缓存中是否有该对象,如果没有,就把它移到缓存中。在此之后缓存中有超过 k个对象,则应移除最近使用最少的一个。换句话说,我们会删除上次查询时间最短的对象。