lundi 22 février 2016

Design Pattern: Cache and Context

A question about a design pattern.

I have a DataManager that uses a cache DataCache that is valid for a given context (in my case, a date).

Should my DataCache store the context under which the data cached is valid, or is it better to leave it only up to the DataManager to know when the DataCache needs to be reset? I feel that having the Context in the Cache as well means more unnecessary maintenance, but maybe there is a good reason to have it in there.

A small point, but wondering what best practice would be here.

Example:

public class DataManager {
    DateTime context;
    DataCache cache;
}

public class DataCache {
    Dictionary dict;
}

or

public class DataManager {
    DateTime context;
    DataCache cache;
}

public class DataCache {
    DateTime context;  // note that we store the context here as well
    Dictionary dict;
}

Aucun commentaire:

Enregistrer un commentaire