From comments, here's the bones of how I do a RAMDisk setup & copy back.
It's not the complete structure, so won't compile as it stands [there will be many missing declarations, as I have a whole set of other structures before I get to this bit, that aren't generic enough to be worth copying in], but gives the routines for creation, copy out & copy back. Save it as an application & launch this instead of your app.
There's also no provision in it for telling your app to use it - that, for me, is a separate structure just using the app's prefs & some —settings
instructions at launch.
It's also set to cover if a mismatch occurs - that's because I have several versions of that particular app, & caches should not be mixed. You can probably leave that section out.
-- RAM Disk setup
set copying to 0
if not {exists disk RAMDisk} then
set VolumeName to RAMDisk
set SizeInMB to 1024
-- can choose size using this dialog
--display dialog "RAM Disk Size:" default answer SizeInMB buttons {"OK", "Cancel"}
set NumSectors to ((2 * 1024 * SizeInMB))
set DeviceName to do shell script "hdid -nomount ram://" & NumSectors
tell current application to do shell script "diskutil eraseVolume 'HFS+' '" & VolumeName & "' " & DeviceName
set foundDisk to false
repeat until (foundDisk = true)
if exists disk RAMDisk then
foundDisk = true
delay 1
-- do copy...
duplicate full_path to disk RAMDisk
exit repeat
else
delay 1 -- waiting for RAM disk to appear, if it's slow
end if
end repeat -- end disk wait
else -- if RAMDisk exists already
set p to (folders of disk RAMDisk)
if (exists folder cache_name of disk RAMDisk) then
if p is {} then -- disk's empty
duplicate full_path to disk RAMDisk
end if
else -- if not (exists folder cache_name of disk RAMDisk) then
display alert "RAM Disk contents are from a different version.\nErasing first..." giving up after 4
try --deletes entire contents of RAMDisk, doesn't throw to Trash
--Folder in Trash can still cause "disk full" error.
--'quoted form' in shell scripts (unix) enables spaces in file names (ie RAMDisk name)
tell current application to do shell script "rm -rf Volumes/" & quoted form of RAMDisk & "/"
end try
duplicate full_path to disk RAMDisk
delay 2
end if -- end cache name check
end if -- end RAMDisk check
(*at this point, launch your app, the script will sit & wait for it to quit*)
-- after app quits, copy back & tidy up
display dialog "Quitting or just restarting 'app'?" buttons {"Quitting", "restarting"} ¬
default button "Quitting" giving up after 30
set thebutton to button returned of result as string
if thebutton is "Quitting" then
set toCopy to true -- to test for copyback
if folder backup_location exists then
display dialog "Safety folder already exists\nDelete & continue copy-back or just quit?" buttons {"Delete", "Just Quit"} default button "Delete" giving up after 30
set thebutton to button returned of result as string
if thebutton is "Delete" then
delete folder backup_location
else
set toCopy to false -- will bypass copyback
end if
end if
if toCopy is true then
-- set a backup folder name before copying
set name of folder full_path to cache_name & " - old"
delay 1
duplicate contents of folder cache_name of disk RAMDisk to folder custom_caches_base_path
delay 1
delete folder backup_location
end if
end if -- end quit sequence
Er.. how big do you plan to have the Ramdisk? Ramdisk is only as big as your RAM. Mac SSD smallest size is 128GB, unless you plan to have 128GB of RAM? I doubt what you want is even possible.. and if you think about it, RAID1 on RAMDISK and SSD, means the RAID set can only work as fast as the slowest component, which is the SSD. You won't get any performance gain, even assuming it is even possible. – Darius – 2016-03-03T11:38:54.983
Thought I can use a software raid (do not know if I am able to use only certain partitions in a hardware raid) to use only one partition with osx installed + some apps (ca. 30GB?). I have 64GB Ram and would use 30GB for RAMDisk (in a RAID 1 with SSD-Partition of equal size). Another possibility could be to buy a small 32GB SSD for that. Thought with "--write-mostly / --write-behind" it is possible to delay the data replication a bit (to buy the ssd some time to cope with the ramdisk). – mfuesslin – 2016-03-03T11:45:59.743
1Technically this might be possible. If you have two 'drives' (one th ramdisk and one a partition on the SSD - no need to use all of the SSDs space). But it might be more useful to use the standard trick for persistent ramdisks. Akak boot, (automatically) copy data to ramdisk. And on shutdown have a copy back to permanent storage. – Hennes – 2016-03-03T11:49:48.557
@Hennes - that's how I deal with a rather thrashy cache for one application I use. Create RAMDisk & copy out at launch, launch app. At quit, write back to a duplicate cache folder, then after safely copied, swap folders & erase the older one. – Tetsujin – 2016-03-03T11:58:45.817
@Hennes - But then I am not able to speed up OSX environment... Ok its fast enough already but would be still nice to have things opened instantly. But maybe I am able to load a ramdisk after boot and then copy most used apps in there and create a symlink to their pendants in the ramdisk to get them fast started? But then spotlight needs to reindex to let me open the "right" safari (in ram and not the one on my ssd)... mhm... any tricks how this could be an automatic workflow? Should I put the ssd-safari in a non-compressing zip so it is no longer visible to spotlight (so only ram-version is?) – mfuesslin – 2016-03-03T12:01:48.807
@Tetsujin - do you have written scripts for that workflow? Is there a chance to get a look on them? What if you "forget" to close the apps and shutdown your mac? Are you able to block shutdown process to get things safely written back to persistent storage? – mfuesslin – 2016-03-03T12:04:46.477
I do - but it's just a cache, the location of which is pre-determined in the app's prefs, so I'm not doing anything difficult like symlinking. I run it from Applescript, so the script simply stays open until the app quits, then offers to copy back, so it will hold up a shut down/reboot by keeping the dialog up & not quitting, should I do it accidentally. – Tetsujin – 2016-03-03T12:14:58.210