Skip to main content

A cached-property decorator.

Project description

Cached Property

This module adds a decorator cached_property and a function drop_cache.

Example

from cached_property import cached_property, drop_cache
import time

class Dummy:
    @cached_property
    def the_answer(self):
        time.sleep(0.5)
        return 42

dummy = Dummy()
t0 = time.time()
err = dummy.the_answer
dt = time.time()-t0
print(dt)
# dt -> ~0.5 seconds
t0 = time.time()
err = dummy.the_answer
dt = time.time()-t0
print(dt)
# dt -> ~1e-6 seconds
drop_cache(dummy, 'the_answer')
t0 = time.time()
err = dummy.the_answer
dt = time.time()-t0
print(dt)
# dt -> ~0.5 seconds

License and Copyright

Copyright 2019 Brain Electrophysiology Laboratory Company LLC

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this module or the code within it except in compliance with the License.

You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Files for cached-property-bel, version 1.0.1
Filename, size File type Python version Upload date Hashes
Filename, size cached_property_bel-1.0.1-py3-none-any.whl (4.5 kB) File type Wheel Python version py3 Upload date Hashes View
Filename, size cached_property_bel-1.0.1.tar.gz (2.6 kB) File type Source Python version None Upload date Hashes View

Supported by

Pingdom Pingdom Monitoring Google Google Object Storage and Download Analytics Sentry Sentry Error logging AWS AWS Cloud computing DataDog DataDog Monitoring Fastly Fastly CDN DigiCert DigiCert EV certificate StatusPage StatusPage Status page