Comments (5)
misc.memoize
和 functools.lru_cache
也很相似。有什么优点吗?
from pydu.
Well, I reimplement exception.ignore
, so that it is same to contextlib.suppress
on Python 3. But on Python 2, exception.ignore
is still implement by self due to there is not contextlib.suppress
.
from pydu.
misc.memoize
aims to cache a value returned by method, so that when we use the method next time, it will just return the cached value.
Meanwhile, functools.lru_cache
aims to cache least recently used value using LRU algorithm. See wiki. If we don't use the value frequently, the cache will be gone. And when we call the method next time, it will re-calculate because of no cache value exists.
from pydu.
但 lru_cache
可以设置缓存大小啊,只要设置为 None 就不会抛弃过去的值了。
from pydu.
设置为 None
确实能达到效果,但这就有点类似于“杀鸡用牛刀”的感觉。之所以有 msc.memoize
是处于这样的考量:
functools.lru_cache
在Python 3中才有,在Python 2中需额外实现- 针对单纯缓存函数调用结果来说,LRU算法尽管能解决问题,但大材小用了,显得有些复杂
from pydu.
Related Issues (3)
- bug: HOT 1
- python2 os has no attribute with link HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from pydu.