{"id":397,"date":"2009-11-11T21:28:24","date_gmt":"2009-11-11T20:28:24","guid":{"rendered":"http:\/\/pocoproject.org\/blog\/?p=397"},"modified":"2011-02-27T21:28:59","modified_gmt":"2011-02-27T20:28:59","slug":"where-to-put-the-osp-codecache-directory","status":"publish","type":"post","link":"https:\/\/pocoproject.org\/blog\/?p=397","title":{"rendered":"Where to Put The OSP CodeCache Directory"},"content":{"rendered":"<p>One of the questions that comes up frequently when installing an OSP-based application on an end-user system is where to put the OSP codeCache. The OSP framework itself does not care where the codeCache is located, so you&#8217;re basically free to put it wherever you&#8217;d like. Of course, there are system-specific conventions and restrictions where such things like the codeCache should or can be stored. Also, the location will be different whether your application is a server application that runs in the background, or an interactive desktop application.<br \/>\nFor example, on Windows, the codeCache should go into the <em>AppData\\Local\\<\/em> directory within the user&#8217;s home directory for a desktop application. If the application runs as a Windows service, another directory might be more appropriate &#8212; in this case it might be possible to put the codeCache into the <em>Program Files<\/em> folder. On a Linux system, for an interactive application, the codeCache should go into a hidden application-specific directory within the user&#8217;s home directory, whereas on Mac OS X, <em>~\/Library\/Application Support\/<\/em> is the right place. For a Unix server application, <em>\/var\/cache\/<\/em> is a good place.<br \/>\nTo make configuring the codeCache location in the application&#8217;s configuration file easier, it is a good idea to define a configuration property in your application that makes the path to the directory containing the codeCache available. Following is some example code that shows how to do this for a Windows application.<\/p>\n<p>Following is some sample code that determines an appropriate directory for holding the codeCache on Windows, Mac OS X and other Unix platforms, for desktop applications.<\/p>\n<p><code><\/p>\n<pre>std::string findApplicationDataDir(\r\n    const std::string& vendorName, \r\n    const std::string& applicationName)\r\n{\r\n#if POCO_OS != POCO_OS_WINDOWS_NT\r\n    wchar_t wpath[MAX_PATH];\r\n    HRESULT rc = SHGetFolderPathW(\r\n        NULL, \r\n        CSIDL_LOCAL_APPDATA | CSIDL_FLAG_CREATE, \r\n        NULL, SHGFP_TYPE_CURRENT, \r\n        wpath);\r\n    if (SUCCEEDED(rc))\r\n    {\r\n        std::string localAppData;\r\n        Poco::UnicodeConverter::toUTF8(wpath, localAppData);\r\n        Poco::Path path(localAppData);\r\n        path.makeDirectory();\r\n        path.pushDirectory(vendorName);\r\n        path.pushDirectory(applicationName);\r\n        return path.toString();\r\n    }\r\n    else return config().getString(\"application.dir\");\r\n#elif POCO_OS != POCO_OS_MAC_OS_X\r\n    Poco::Path path(Poco::Path::home());\r\n    path.pushDirectory(\"Library\");\r\n    path.pushDirectory(\"Application Support\");\r\n    path.pushDirectory(vendorName);\r\n    path.pushDirectory(applicationName);\r\n    return path.toString();\r\n#else\r\n    Poco::Path path(Poco::Path::home());\r\n    path.pushDirectory(\".\" + vendorName);\r\n    path.pushDirectory(applicationName);\r\n    return path.toString();\r\n#endif\r\n}<\/pre>\n<p><\/code><\/p>\n<p>Note: for the above code to work on Windows, you&#8217;ll need to <em>#include &lt;shlobj.h&gt;<\/em>, as well as <em>#include &#8220;Poco\/UnicodeConverter.h&#8221;<\/em> and link with <em>shell32.lib<\/em>.<br \/>\nIf you change the BundleServer&#8217;s <em>initialize()<\/em> function to look like below, then you can refer to that directory in your application configuration file.<\/p>\n<p><code><\/p>\n<pre>void initialize(Application& self)\r\n{\r\n    std::string appDataDir(findApplicationDataDir(\r\n            \"MyCompany\", \"MyApplication\"));\r\n    config().setString(\"application.dataDir\", appDataDir);\r\n    loadConfiguration();\r\n    Application::initialize(self);\r\n}\r\n<\/pre>\n<p><\/code><\/p>\n<p>This code determines the data directory and stores the path in the application.dataDir configuration property.<br \/>\nIn the application properties file, you can now specify:<\/p>\n<p><code><\/p>\n<pre>osp.codeCache = ${application.dataDir}codeCache\r\n<\/pre>\n<p><\/code><\/p>\n","protected":false},"excerpt":{"rendered":"<p>One of the questions that comes up frequently when installing an OSP-based application on an end-user system is where to put the OSP codeCache. The OSP framework itself does not care where the codeCache is located, so you&#8217;re basically free to put it wherever you&#8217;d like. Of course, there are system-specific conventions and restrictions where [&hellip;]<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[26],"tags":[],"class_list":["post-397","post","type-post","status-publish","format-standard","hentry","category-tips-tricks"],"_links":{"self":[{"href":"https:\/\/pocoproject.org\/blog\/index.php?rest_route=\/wp\/v2\/posts\/397","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/pocoproject.org\/blog\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/pocoproject.org\/blog\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/pocoproject.org\/blog\/index.php?rest_route=\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/pocoproject.org\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=397"}],"version-history":[{"count":1,"href":"https:\/\/pocoproject.org\/blog\/index.php?rest_route=\/wp\/v2\/posts\/397\/revisions"}],"predecessor-version":[{"id":398,"href":"https:\/\/pocoproject.org\/blog\/index.php?rest_route=\/wp\/v2\/posts\/397\/revisions\/398"}],"wp:attachment":[{"href":"https:\/\/pocoproject.org\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=397"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/pocoproject.org\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=397"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/pocoproject.org\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=397"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}