0

I have a requirement like

For the first time I run the process, I need to set a=1

And for the remaining times I run the same process, I need to set a=2

Is it possible to maintain cache that tells the process is ran for second time.

I don't want another physical file to be created in my directory structure.

I searched in internet, but found always the cache within the process.

Thanks in advance

1
  • 3
    Physical files are the best way to keep data around as far as I know ... Commented Dec 5, 2013 at 7:55

3 Answers 3

7

The ways to preserve data between totally separate executions of a process are:

  • Saving a file.

  • Handing the data off to another process such as a Memcached or Redis instance, or a database, which will keep the data in memory and/or write it to disk somewhere.

  • Recording the data in some other, more unusual way such as changing the environment of the running operating system, printing out the data or otherwise displaying it so that the human operator can keep track of it, or something like that.

When you use the word 'cache' and state that you do not wish to write the data to disk, the first thing that comes to mind is memcached or some other in-memory cache. But any file-based solution will certainly be less complex than setting up and maintaining an in-memory key-value store.

Which solution you choose depends in part on what 'second time' means. Second time ever? Second time ever on a given computer? Second time since reboot? Since manual reset? Different methods of recording data are suited to different storage requirements.

Sign up to request clarification or add additional context in comments.

1 Comment

+1 for going the extra mile in explaining there isn't one solution for everything
1

If your application is really just a=1 versus a=2 using a file is as good as anything, otherwise consult here: http://docs.python.org/2/library/persistence.html for other persistence methods.

Comments

0

Data cached inside the process dies along with the process. You'll have to cache this info elsewhere since you want it to persist longer than the process lives. A file seems reasonable.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.