Opened 7 years ago

Last modified 5 years ago

#16505 needs_work enhancement

Add unset_cache() to remove single keys from a cached_method

Reported by: saraedum Owned by:
Priority: minor Milestone: sage-7.0
Component: misc Keywords: cached_method
Cc: Merged in:
Authors: Julian Rueth Reviewers:
Report Upstream: N/A Work issues:
Branch: u/saraedum/ticket/16505 (Commits) Commit: 9cee22e0b83fb18a699df9d898f5d437b5cdb2a2
Dependencies: Stopgaps:

Description (last modified by saraedum)

A cached_method's clear_cache() clears the entire dictionary of a cached_method. Currently, there is no way to only remove some keys. This is sometimes necessary if values in the cache are not usable anymore (e.g. because they are defined in some external expect interface but the external session is not running anymore).

Change History (16)

comment:1 Changed 7 years ago by saraedum

  • Description modified (diff)
  • Status changed from new to needs_review
  • Summary changed from Modify cached_method's clear_cache() to remove single keys to Add unset_cache() to remove single keys from a cached_method

comment:2 Changed 7 years ago by saraedum

  • Branch set to u/saraedum/ticket/16505
  • Created changed from 06/20/14 18:54:16 to 06/20/14 18:54:16
  • Modified changed from 06/20/14 19:33:25 to 06/20/14 19:33:25

comment:3 Changed 7 years ago by git

  • Commit set to 7b01ec82ee12fbefeb3f475255b6e09562e02a45

Branch pushed to git repo; I updated commit sha1. New commits:

7b01ec8Merge branch 'develop' into ticket/16505

comment:4 Changed 6 years ago by saraedum

  • Description modified (diff)

comment:5 Changed 6 years ago by git

  • Commit changed from 7b01ec82ee12fbefeb3f475255b6e09562e02a45 to 91e09ce01114b7cf038332bb976a4ccfa3945a82

Branch pushed to git repo; I updated commit sha1. New commits:

91e09ceMerge branch 'develop' into ticket/16505

comment:6 Changed 6 years ago by vbraun_spam

  • Milestone changed from sage-6.3 to sage-6.4

comment:7 Changed 6 years ago by ncohen

  • Status changed from needs_review to needs_work

From the looks of the function set_cache just above the one that you define, it seems that you should also handle the case of non-hashable keys.

Nathann

comment:8 Changed 5 years ago by git

  • Commit changed from 91e09ce01114b7cf038332bb976a4ccfa3945a82 to 01f8fceab6ffb3cf688968116a6ba7bd2649ab59

Branch pushed to git repo; I updated commit sha1. New commits:

01f8fceMerge branch 'develop' into t/16505/ticket/16505

comment:9 Changed 5 years ago by git

  • Commit changed from 01f8fceab6ffb3cf688968116a6ba7bd2649ab59 to 29d8e83921211b831f25272107501a8c1436dab0

Branch pushed to git repo; I updated commit sha1. New commits:

29d8e83handle unhashable keys in unset_cache

comment:10 Changed 5 years ago by jdemeyer

  • Dependencies set to #19768

Please rebase this on top of #19768.

comment:11 Changed 5 years ago by jdemeyer

  • Dependencies #19768 deleted

comment:12 Changed 5 years ago by git

  • Commit changed from 29d8e83921211b831f25272107501a8c1436dab0 to 0bcb93f0ad42631064bfb0bcc1fcc61634536412

Branch pushed to git repo; I updated commit sha1. New commits:

0bcb93fMerge branch 'develop' into t/16505/ticket/16505

comment:13 Changed 5 years ago by git

  • Commit changed from 0bcb93f0ad42631064bfb0bcc1fcc61634536412 to 9cee22e0b83fb18a699df9d898f5d437b5cdb2a2

Branch pushed to git repo; I updated commit sha1. New commits:

9cee22efix build error

comment:14 Changed 5 years ago by saraedum

  • Status changed from needs_work to needs_review

comment:15 Changed 5 years ago by jdemeyer

Please use the get_key_args_kwds() and dict_key() functions added recently to cached functions.

comment:16 in reply to: ↑ description Changed 5 years ago by jdemeyer

  • Milestone changed from sage-6.4 to sage-7.0
  • Status changed from needs_review to needs_work

Replying to saraedum:

Currently, there is no way to only remove some keys. This is sometimes necessary if values in the cache are not usable anymore

For this use case, I see no reason to raise KeyError when the key does not exist: I would just ignore non-existing keys.

You should add doctests showing that this also works for a weak cached function and a cached method (not just plain cached functions).

Note: See TracTickets for help on using tickets.