Coder Social home page Coder Social logo

Comments (5)

Cologler avatar Cologler commented on July 4, 2024

misc.memoizefunctools.lru_cache 也很相似。有什么优点吗?

from pydu.

Prodesire avatar Prodesire commented on July 4, 2024

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.

Prodesire avatar Prodesire commented on July 4, 2024

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.

Cologler avatar Cologler commented on July 4, 2024

lru_cache 可以设置缓存大小啊,只要设置为 None 就不会抛弃过去的值了。

from pydu.

Prodesire avatar Prodesire commented on July 4, 2024

设置为 None 确实能达到效果,但这就有点类似于“杀鸡用牛刀”的感觉。之所以有 msc.memoize 是处于这样的考量:

  • functools.lru_cache 在Python 3中才有,在Python 2中需额外实现
  • 针对单纯缓存函数调用结果来说,LRU算法尽管能解决问题,但大材小用了,显得有些复杂

from pydu.

Related Issues (3)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.