forked from tilemill-project/tilemill
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Split model cache into separate file and use mixin/override style for…
… models-server.
- Loading branch information
Young Hahn
committed
Feb 21, 2011
1 parent
49a0258
commit 5217244
Showing
8 changed files
with
75 additions
and
78 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
// Cache | ||
// ----- | ||
// Provides a model instance cache for the server. Used to store and retrieve a | ||
// model instance in memory such that the same model is referenced in separate | ||
// requests as well as in other long-running processes. | ||
// | ||
// The main use-case in TileMill for this instance cache is triggering a model | ||
// `delete` event when a DELETE request is received. In the case of Exports, | ||
// this event is used to terminate and worker processes associated with the | ||
// Export model being deleted. | ||
var models = require('models'); | ||
module.exports = { | ||
cache: {}, | ||
get: function(type, id) { | ||
if (this.cache[type] && this.cache[type][id]) { | ||
return this.cache[type][id]; | ||
} | ||
this.cache[type] = this.cache[type] || {} | ||
this.set(type, id, new models[type]({id: id})); | ||
return this.cache[type][id]; | ||
}, | ||
set: function(type, id, model) { | ||
this.cache[type] = this.cache[type] || {} | ||
this.cache[type][id] = model; | ||
return this.cache[type][id]; | ||
}, | ||
del: function(type, id) { | ||
if (this.cache[type][id]) { | ||
delete this.cache[type][id]; | ||
} | ||
} | ||
}; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters