An implementation of memoization technique for Django

Overview
Comments
  • Is memoize refresh possible ?

    Is memoize refresh possible ?

    Hi,

    Is memoize refresh possible ? In order to doesn't have cache interrupt. For example, I set a one day cache and a task that start 10 minutes before cache invalidation to refresh it by myself. But if I delete it and re-run the function, I'll have interruption. Am I clear ? :smile:

    Thank you.

    opened by toxinu 9
  • Replace getargspec with getfullargspec

    Replace getargspec with getfullargspec

    Looks like getargspec has been deprecated for python versions >= 3.0. https://docs.python.org/3/library/inspect.html#inspect.getargspec This was throwing some warnings for me when writing unit tests for a project I'm working on. I figured I could silence the warnings or do this PR. Here ya go.

    opened by acrfordyce 5
  • Add support for boolean convert_to_unicode flag

    Add support for boolean convert_to_unicode flag

    This PR is intended to add support for a boolean convert_to_unicode flag, which will enable us to specify whether or not to convert string-objects to unicode when executing make_cache_key for a particular function that has been memoized.

    EDIT: This PR was implemented in order to resolve the following issue when using django-memoize under Python 2:

    In [1]: from memoize import memoize
    
    In [2]: import random
    
    In [3]: @memoize(timeout=300)
       ...: def f(key):
       ...:     return random.randrange(100000, 999999)
       ...:
    
    In [4]: f('abc')
    Out[4]: 656674
    
    In [5]: f(u'abc')
    Out[5]: 749955
    
    In [6]: f('abc')
    Out[6]: 656674
    
    In [7]: f(u'abc')
    Out[7]: 749955
    

    ...in particular, even though 'abc' and u'abc' are logically the same string, we create two separate cache entries simply based on the fact that one key is a str object and the other is a unicode object.

    This phenomenon currently affects any piece of the library that makes use of the make_cache_key method (i.e. memoize, delete_memoized, etc.). For example, if we run f('abc') (in one file) and then run delete_memoized(f, u'abc') (in some other file), then the cache entry will not be properly cleared.

    opened by GotoCode 4
  • Django-Memoize doesn't work on type annotated functions

    Django-Memoize doesn't work on type annotated functions

    I have a function with the following signature:

    @memoize(timeout=300) def _start_sequence(self, exam: Exam):

    The moment I try to run the function with the annotation I get the following error:

    Function has keyword-only arguments or annotations, use getfullargspec() API which can support them

    If I remove the type annotation everything works as expected. Given that type annotations have become quite useful with Python 3.5 it would be intrestring to support them.

    Unfortunately I see that the required function is only supported in Python 3: inspect.getfullargspec but with some Six magic we can probably make it work.

    If you're interested and don't object to the inclusion of Six as an additional dependency I could create a pull request. Let me know!

    opened by LaurensBosscher 3
  • Support memoizing None return value

    Support memoizing None return value

    There are cases where the return value of a function is None and can/should be cached as such.

    This preserves the existing behavior of returning None from a memoizer.get (and not caching None return values) unless the user has chosen to memoize None values by instantiating Memoize with memoize_none_values=True.

    I believe that the default for this arg could be changed to True, as the only case where users would be affected is if they are accessing memoizer.get directly.

    opened by brechin 3
  • Git tag of releases

    Git tag of releases

    Could you start doing git tags of pypi releases again so it's easy to match up code changes with package releases? The last git tag/GitHub release is currently 1.2.0 from 2015 (https://github.com/tvavrys/django-memoize/releases)

    opened by therefromhere 2
  • Deprecation warning

    Deprecation warning

    I see the following deprecation warning in Python 3.5.2:

    python3.5/site-packages/memoize/__init__.py:28: DeprecationWarning: inspect.getargspec() is deprecated, use inspect.signature() instead argspec = inspect.getargspec(f)

    opened by wrvdklooster 2
  • Added handling of None values in cache

    Added handling of None values in cache

    This adds handling of None values. Use case is:

    Sample memoized function like:

       @memoize(timeout=100)
       def sample(param):
           return Model.objects.filter(field=param).first()
    

    In case sample function returns None this None is stored in the cache by memoize. However in case of further calls to the sample function, memoize internally does rv = self.get(...) and then if rv is None: then execute function again. This means it treats None as no value in cache. Provided fix changes this behaviour to clearly differentiate between "no value in cache" and "None in cache" situations.

    opened by restless 2
  • *args are ignored by memoize.

    *args are ignored by memoize.

    Is it intentional that the *args after the declared arguments are ignored by the memoize decorator, or is that a bug? Below is an example in an ipython shell with python==2.7.6, django==1.4.22 of how memoize isn't taking into account the *args.

    In [16]: @memoize()
    def func(*args, **kwargs):
        return args, kwargs
       ....:
    
    In [17]: func(1)
    Out[17]: ((1,), {})
    
    In [18]: func(2)
    Out[18]: ((1,), {})
    
    In [19]: func(1, 2)
    Out[19]: ((1,), {})
    
    In [20]: func(1, one=1)
    Out[20]: ((1,), {'one': 1})
    
    opened by patgmiller 2
  • Please, mention in the docs which versions of Django are supported

    Please, mention in the docs which versions of Django are supported

    For instance, it doesn't work with 1.4.

    I see that the test_settings were created with Django 1.6, but whether it does work with Django 1.5 (likely it does) and Django 1.7 (not sure) - that's the question.

    IMHO, that's something worth mentioning at the very start of the documentation.

    opened by barseghyanartur 2
  • Accept cache parameter on Memoize constructor

    Accept cache parameter on Memoize constructor

    I have a use case where I need to memoize using a DatabaseCache backend.

    It would be great if Memoizer constructor accepted a cache parameter, allowing the developer to specify a custom cache like: db_memoizer = Memoizer(cache=get_cache('db_cache'))

    Also, it would be interesting to add a cache parameter to @memoize decorator. What do you think?

    opened by fjsj 2
  • Django-less fork

    Django-less fork

    Hello, We found this library useful (thank you!), but we needed it outside a Django context, so we forked it and adapted it. In case you are interested in maintaining the fork please let me know, otherwise we plan to publish the fork ourselves (following the license terms, of course). :)

    opened by abotto-amadeus 0
  • Potential bug computing len of argspec.defaults

    Potential bug computing len of argspec.defaults

    TypeError object of type 'NoneType' has no len()

    https://docs.python.org/3.8/library/inspect.html?highlight=inspect#inspect.getfullargspec https://docs.python.org/3.8/library/inspect.html?highlight=inspect#inspect.getargspec

    defaults is an n-tuple of default argument values corresponding to the last n positional parameters, or None if there are no such defaults defined

    https://github.com/unhaggle/django-memoize/blob/1ca9af73adf3e5e336aafe85b82993a0a3a66a77/memoize/init.py?_pjax=%23repo-content-pjax-container#L250

    elif abs(i - args_len) <= len(argspec.defaults)

    Possible fix:

    elif abs(i - args_len) <= len(argspec.defaults if argspec.defaults else [])

    opened by slothyrulez 0
  • Excessive counts on cache_table

    Excessive counts on cache_table

    Something in memoize seems to do a count on the cache_table all the time, why ?

    I see this all the time:

    SELECT COUNT(*) FROM "cache_table"; args=None

    as my table is large it takes 4 seconds on our system.

    opened by jimmy927 0
  • @memoize func not cache as which timeout param set.

    @memoize func not cache as which timeout param set.

    Hi, I found that @memoize func can't cache a function's result as which the timeout param set.When I set the timeout to 25 * 3600,I found that it ca't cache such a long time(25 hours).Dose this is a bug or something I had missed?

    opened by wsf1990 0
Python disk-backed cache (Django-compatible). Faster than Redis and Memcached. Pure-Python.

DiskCache is an Apache2 licensed disk and file backed cache library, written in pure-Python, and compatible with Django.

Grant Jenks 1.7k Jan 5, 2023
An ORM cache for Django.

Django ORMCache A cache manager mixin that provides some caching of objects for the ORM. Installation / Setup / Usage TODO Testing Run the tests with:

Educreations, Inc 15 Nov 27, 2022
A Redis cache backend for django

Redis Django Cache Backend A Redis cache backend for Django Docs can be found at http://django-redis-cache.readthedocs.org/en/latest/. Changelog 3.0.0

Sean Bleier 1k Dec 15, 2022
johnny cache django caching framework

Johnny Cache is a caching framework for django applications. It works with the django caching abstraction, but was developed specifically with the use

Jason Moiron 304 Nov 7, 2022
A tool for light-duty persistent memoization of API calls

JSON Memoize What is this? json_memoize is a straightforward tool for light-duty persistent memoization, created with API calls in mind. It stores the

null 1 Dec 11, 2021
Ceaser-Cipher - The Caesar Cipher technique is one of the earliest and simplest method of encryption technique

Ceaser-Cipher The Caesar Cipher technique is one of the earliest and simplest me

Lateefah Ajadi 2 May 12, 2022
Pytorch implementation of AngularGrad: A New Optimization Technique for Angular Convergence of Convolutional Neural Networks

AngularGrad Optimizer This repository contains the oficial implementation for AngularGrad: A New Optimization Technique for Angular Convergence of Con

mario 124 Sep 16, 2022
Partial implementation of ODE-GAN technique from the paper Training Generative Adversarial Networks by Solving Ordinary Differential Equations

ODE GAN (Prototype) in PyTorch Partial implementation of ODE-GAN technique from the paper Training Generative Adversarial Networks by Solving Ordinary

Somshubra Majumdar 15 Feb 10, 2022
Tensorflow Implementation of SMU: SMOOTH ACTIVATION FUNCTION FOR DEEP NETWORKS USING SMOOTHING MAXIMUM TECHNIQUE

SMU A Tensorflow Implementation of SMU: SMOOTH ACTIVATION FUNCTION FOR DEEP NETWORKS USING SMOOTHING MAXIMUM TECHNIQUE arXiv https://arxiv.org/abs/211

Fuhang 5 Jan 18, 2022
An open source machine learning library for performing regression tasks using RVM technique.

Introduction neonrvm is an open source machine learning library for performing regression tasks using RVM technique. It is written in C programming la

Siavash Eliasi 33 May 31, 2022
Python package for stacking (machine learning technique)

vecstack Python package for stacking (stacked generalization) featuring lightweight functional API and fully compatible scikit-learn API Convenient wa

Igor Ivanov 671 Dec 25, 2022
Python Extreme Learning Machine (ELM) is a machine learning technique used for classification/regression tasks.

Python Extreme Learning Machine (ELM) Python Extreme Learning Machine (ELM) is a machine learning technique used for classification/regression tasks.

Augusto Almeida 84 Nov 25, 2022
This code extends the neural style transfer image processing technique to video by generating smooth transitions between several reference style images

Neural Style Transfer Transition Video Processing By Brycen Westgarth and Tristan Jogminas Description This code extends the neural style transfer ima

Brycen Westgarth 110 Jan 7, 2023
CoReNet is a technique for joint multi-object 3D reconstruction from a single RGB image.

CoReNet CoReNet is a technique for joint multi-object 3D reconstruction from a single RGB image. It produces coherent reconstructions, where all objec

Google Research 80 Dec 25, 2022
An experimental technique for efficiently exploring neural architectures.

SMASH: One-Shot Model Architecture Search through HyperNetworks An experimental technique for efficiently exploring neural architectures. This reposit

Andy Brock 478 Aug 4, 2022
Technique for Order of Preference by Similarity to Ideal Solution (TOPSIS)

TOPSIS implementation in Python Technique for Order of Preference by Similarity to Ideal Solution (TOPSIS) CHING-LAI Hwang and Yoon introduced TOPSIS

Hamed Baziyad 8 Dec 10, 2022
This is the code for the EMNLP 2021 paper AEDA: An Easier Data Augmentation Technique for Text Classification

The baseline code is for EDA: Easy Data Augmentation techniques for boosting performance on text classification tasks

Akbar Karimi 81 Dec 9, 2022
An experimental technique for efficiently exploring neural architectures.

SMASH: One-Shot Model Architecture Search through HyperNetworks An experimental technique for efficiently exploring neural architectures. This reposit

Andy Brock 478 Aug 4, 2022
the project for the most brutal and effective language learning technique

- "The project for the most brutal and effective language learning technique" (c) Alex Kay The langflow project was created especially for language le

Alexander Kaigorodov 7 Dec 26, 2021