Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 885645
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T12:56:31+00:00 2026-05-15T12:56:31+00:00

there is a very time-consuming operation which generates a dataset in my package. I

  • 0

there is a very time-consuming operation which generates a dataset in my package. I would like to save this dataset and let the package rebuild it only when I manually delete the cached file. Here is my approach as part of the package:

myDataset = Module[{fname, data}, 
    fname = "cached-data.mx";
    If[FileExistsQ[fname], 
        Get[fname],
        data = Evaluate[timeConsumingOperation[]];
        Put[data, fname];
        data]
];

timeConsumingOperation[]:=Module[{},
    (* lot of work here *)
    {"data"}
];

However, instead of writing the long data set to the file, the Put command only writes one line: “timeConsumingOperation[]”, even if I wrap it with Evaluate as above. (To be true, this behaviour is not consistent, sometimes the dataset is written, sometimes not.)

How do you cache your data?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-15T12:56:32+00:00Added an answer on May 15, 2026 at 12:56 pm

    In the past, whenever I’ve had trouble with things evaluating it is usually when I have not correctly matched the pattern required by the function. For instance,

    f[x_Integers]:= x
    

    which won’t match anything. Instead, I meant

    f[x_Integer]:=x
    

    In your case, though, you have no pattern to match: timeConsumingOperation[].

    You’re problem is more likely related to when timeConsumingOperation is defined relative to myDataset. In the code you’ve posted above, timeConsumingOperation is defined after myDataset. So, on the first run (or immediately after you’ve cleared the global variables) you would get exactly the result you’re describing because timeConsumingOperation is not defined when the code for myDataset is run.

    Now, SetDelayed (:=) automatically causes the variable to be recalculated whenever it is used, and since you do not require any parameters to be passed, the square brackets are not necessary. The important point here is that timeConsumingOperation can be declared, as written, prior to myDataset because SetDelayed will cause it not to be executed until it is used.

    All told, your caching methodology looks exactly how I would go about it.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

There's something very unsatisfactory about this code: /* Given a command string in which
For iPhone game development, seems there are very like functions using CALayer and UIView,
I'd like to learn assembler. However, there are very few resources for doing assembler
There is a very similar question already. One of the solutions uses code like
There is very strange assembly reference problem and loading problem I experience with my
Can an ArrayList of Node contain a non-Node type? Is there a very dirty
There exists a very good talk about C# vs. Java where H.Mössenböck compares the
Are there any c++ networking libs that are very useful and robust? and libs
Very simple question, is there any cloud server enviroments avaliable these days for us
Drupal is very much a Do Everything CMS. There are modules that allow you

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.