Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
basic
Manage
Activity
Members
Code
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Releases
Model registry
Analyze
Contributor analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Admin message
Gitlab Maintenance 11.04.2025 | 20:00 - 23:00 MEZ
Show more breadcrumbs
xrm
basic
Commits
f41cc62d
Commit
f41cc62d
authored
5 years ago
by
Johannes Goderbauer
Browse files
Options
Downloads
Patches
Plain Diff
implemented basic client-global caching mechanisms (2)
parent
e80d1615
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
process/DataCaching_lib/process.js
+52
-28
52 additions, 28 deletions
process/DataCaching_lib/process.js
with
52 additions
and
28 deletions
process/DataCaching_lib/process.js
+
52
−
28
View file @
f41cc62d
import
(
"
system.vars
"
);
function
CachedData
(
pIdentifiyingName
,
pKeepPerLanguage
)
function
CachedData
(
pIdentifiyingName
,
pKeepPerLanguage
,
pLocaleOverride
)
{
this
.
identifyingName
=
pIdentifiyingName
;
this
.
keepPerLanguage
=
pKeepPerLanguage
;
this
.
runningOnServer
=
vars
.
getString
(
"
$sys.isserver
"
)
==
"
true
"
;
if
(
this
.
runningOnServer
)
if
(
pLocaleOverride
)
this
.
locale
=
pLocaleOverride
;
else
if
(
this
.
runningOnServer
)
this
.
locale
=
vars
.
get
(
"
$sys.serverlocale
"
);
else
this
.
locale
=
(
this
.
keepPerLanguage
?
vars
.
get
(
"
$sys.clientlocale
"
)
:
"
_anyLanguage_
"
);
...
...
@@ -15,12 +17,12 @@ function CachedData(pIdentifiyingName, pKeepPerLanguage)
CachedData
.
make
=
function
(
pIdentifiyingName
,
pKeepPerLanguage
,
pDataCallbackFunction
)
{
return
(
new
CachedData
(
pIdentifiyingName
,
pKeepPerLanguage
)).
load
(
pDataCallbackFunction
);
return
(
new
CachedData
(
pIdentifiyingName
,
pKeepPerLanguage
,
null
)).
load
(
pDataCallbackFunction
);
}
CachedData
.
prototype
.
load
=
function
(
pDataCallbackFunction
)
{
//currently it's not possible to cache the data within the serer-context, so in
e
stead the Data-function is called everytime
//currently it's not possible to cache the data within the serer-context, so instead the Data-function is called everytime
if
(
this
.
runningOnServer
)
return
pDataCallbackFunction
.
call
(
this
,
this
.
keepPerLanguage
,
this
.
locale
);
else
...
...
@@ -35,6 +37,8 @@ CachedData.prototype.load = function(pDataCallbackFunction)
}
data
=
pDataCallbackFunction
.
call
(
this
,
this
.
keepPerLanguage
,
this
.
locale
);
if
(
data
==
null
)
throw
new
Error
(
"
use unload instead
"
);
vars
.
set
(
varname
,
data
);
this
.
_register
();
return
data
;
...
...
@@ -48,17 +52,33 @@ CachedData.prototype.unload = function()
this
.
_unregister
();
}
CachedData
.
prototype
.
getVariableIdentifier
=
function
()
{
//keep data per user in a global var to assure that translations and grants are correctly applied
var
PREFIX
=
"
$global.CachedData.
"
;
var
res
=
PREFIX
+
this
.
identifyingName
return
res
;
};
CachedData
.
prototype
.
getVariableName
=
function
()
{
var
PREFIX
=
"
$global.CachedData.
"
;
var
res
=
PREFIX
+
this
.
identifyingName
+
"
.
"
+
this
.
locale
;
var
res
=
this
.
getVariableIdentifier
()
+
"
.
"
+
this
.
locale
;
return
res
;
};
//functions for registry of variables; reserver for later functionality
CachedData
.
prototype
.
_register
=
function
()
{
var
reg
=
CachedData
.
getRegistry
();
reg
.
push
(
this
.
getVariableName
());
vars
.
set
(
CachedData
.
getRegistryName
(),
reg
);
}
//CachedData.prototype._unregister = function(){}
CachedData
.
getRegistryName
=
function
()
{
return
"
$global.CachedDataRegistry
"
;
}
}
;
CachedData
.
getRegistry
=
function
()
{
...
...
@@ -66,25 +86,29 @@ CachedData.getRegistry = function()
if
(
vars
.
exists
(
registryVarname
))
return
vars
.
get
(
registryVarname
);
else
return
{};
}
CachedData
.
prototype
.
_register
=
function
()
{
var
registry
=
CachedData
.
getRegistry
();
if
(
registry
[
this
.
getVariableName
()]
!=
undefined
)
throw
new
Error
(
"
Already registered. cannot register the same object twice
"
);
//TODO: message
else
registry
[
this
.
getVariableName
()]
=
{
keepPerLanguage
:
this
.
keepPerLanguage
};
vars
.
set
(
CachedData
.
getRegistryName
(),
registry
);
};
CachedData
.
prototype
.
_unregister
=
function
()
{
var
registry
=
CachedData
.
getRegistry
();
if
(
registry
[
this
.
getVariableName
()]
==
undefined
)
throw
new
Error
(
"
Item not found. cannot unregister
"
);
//TODO: message
else
delete
registry
[
this
.
getVariableName
()];
vars
.
set
(
CachedData
.
getRegistryName
(),
registry
);
return
[];
};
//
//CachedData.prototype._register = function()
//{
// var registry = CachedData.getRegistry();
//
// if (registry[this.getVariableIdentifier()])
//
// if (registry[this.getVariableName()] != undefined)
// throw new Error("Already registered. cannot register the same object twice");//TODO: message
// else
// registry[this.getVariableName()] = {keepPerLanguage: this.keepPerLanguage};
// vars.set(CachedData.getRegistryName(), registry);
//};
//
//CachedData.prototype._unregister = function()
//{
// var varname = this.getVariableName();
// var registry = CachedData.getRegistry();
// if (registry[varname] == undefined)
// throw new Error("Item not found. cannot unregister");//TODO: message
// else
// delete registry[varname];
// vars.set(CachedData.getRegistryName(), registry);
//};
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment