Python Forum
Speeding up code using cache
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Speeding up code using cache
#1
I'm good with Python and use functions to process large datasets from files, then return the results. I've realized these input files and other parameters don't change often, so I could store the returned results for reuse.

I've used @functools.lru_cache before, but I'm facing a challenge now. Even though file paths (passed as input to my functions) remain the same, sometimes I need to ignore the cached values if the file has been updated since the last call. I don't want to complicate my functions by checking for this.

I'm looking for a caching solution that can handle this. If anyone knows an existing solution, I'd love to hear it, so I don't have to create one from scratch.
Reply
#2
I think creating your own is the way to go here. lru_cache doesn't have any method to invalidate individual entries. Even if it did, you'd already have to have to stat the file and manage the logic to detect when to invalidate them.
Gribouillis likes this post
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Opinion: how should my scripts cache web download files? stevendaprano 0 751 Dec-17-2022, 12:19 AM
Last Post: stevendaprano
  main libvlc error: stale plugins cache: schascheck 2 7,772 Dec-27-2020, 05:24 PM
Last Post: schascheck
  Clear Cache Path sportcardinal 0 1,639 Jul-05-2020, 05:11 PM
Last Post: sportcardinal
  How to print cache from Decorators with Memoization OlgaM 2 2,108 Jan-29-2020, 05:06 PM
Last Post: OlgaM
  pip cache millpond 3 8,263 Jul-22-2019, 01:12 AM
Last Post: millpond
  python cache for small integer Uchikago 1 2,525 Jun-27-2019, 05:32 PM
Last Post: ichabod801
  Error in request, cache key a21250450 2 3,156 Apr-02-2019, 11:20 AM
Last Post: a21250450
  Clear cache blackclover 0 2,806 May-09-2018, 12:13 AM
Last Post: blackclover
  Speeding up Brute force password guesser Gamervote 5 6,903 Jul-20-2017, 02:52 PM
Last Post: nilamo
  Create cache script AgatheYou 1 3,693 Apr-04-2017, 02:15 PM
Last Post: sparkz_alot

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020