Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

Ursadorable

macrumors 6502a
Original poster
Jul 9, 2013
688
975
The Frozen North
I like to move the browser's cache directory to a RAM disk to save unnecessary wear and tear on the SSD.

I noticed that when I make a symlink from:

/Users/<username>/Library/Caches/Microsoft Edge/Default/Cache to my ram disk, Edge refuses to write to the ram disk. If I "touch" a file via the symlink path, it creates the file without issues.

The destination directory is 777, so there should be no permission issues, yet Edge will not right to it.

If I delete the symlink, Edge will create a new cache directory and write to it.

Any ideas why Edge would refuse to write to a symlink'd directory?

Thanks for any insight.

Regards.

Edit: I should mention I'm using Big Sur.. but that shouldn't make a difference.
 
It might be doing something dumb, and the result says "it's a symlink", which is interpreted as "it's not a directory", and it fails. For example, the stat(2) system func will follow symlinks in the leaf element, while lstat(2) doesn't. So if it's doing lstat() instead of stat(), it's doing the wrong thing. I've seen bugs like this before.

Try moving the symlink up one name element, and see if that makes it work. For example, if this is the current symlink:
/Users/<username>/Library/Caches/Microsoft Edge/Default/Cache
change it so this is a symlink:
/Users/<username>/Library/Caches/Microsoft Edge/Default/
then move the necessary files and dirs into the symlinked dir. In short, make sure the symlink isn't in the leaf element of the pathname.

If that still fails, you could try further moves up the pathname elements. I wouldn't go any farther than the "Microsoft Edge" dir in "Library/Caches". Changing Library/Caches to a symlink might bork more things than just MS Edge.


Another possibility is the 777 permissions. That might be too open, and Edge is doing some kind of rudimentary security enforcement, where if it thinks the permissions are too wide it won't put things there.

You could test this hypothesis by eliminating all symlinks, then setting the permissions of the Default/Cache dir to 777 (wide open). If Edge barfs on that, then copy the exact permissions (and ownership) from the original dir and apply to your target dir.
 
I tried your suggestions, made the symlink one directory up using Default as the symlink.

Edge created the directory "Code Cache", but not "Cache". I manually created the Cache directory on the ramdisk, with the same permissions and ownership as Edge would use on the SSD. It still refused to use it. :(

It has to be some Edge oddity, as I've used symlinks for decades and never had an issue until now.
 
You might be able to mount a disk-image residing on the RAM-disk to the "Library/Caches/Microsoft Edge/Default/Cache" dir. You'll likely need to dig into the 'hdiutil' and 'mount' cmds to learn more, and probably do some experiments.

The reason for using a disk-image is because mounting only works on an entire volume, not a portion. It's not possible to "mount" a dir residing on the RAM-disk to a dir on another file-system.
 
You might be able to mount a disk-image residing on the RAM-disk to the "Library/Caches/Microsoft Edge/Default/Cache" dir. You'll likely need to dig into the 'hdiutil' and 'mount' cmds to learn more, and probably do some experiments.

The reason for using a disk-image is because mounting only works on an entire volume, not a portion. It's not possible to "mount" a dir residing on the RAM-disk to a dir on another file-system.

Interesting, I never thought of that. I'll have to look into it.

Thanks.
 
Bash:
#!/bin/bash
# Create RAM Disk

RDISKSIZE=8388608 #4GB
RDISKNAME="RamDisk"
CACHELOCATION="/Users/$USER/Library/Caches/Microsoft Edge/Default"

# Create the RAM Disk

if [ ! -d "/Volumes/$RDISKNAME" ]
    then
        echo "Creating volume /Volumes/$RDISKNAME..."
        diskutil erasevolume HFS+ "$RDISKNAME" `hdiutil attach -nomount ram://$RDISKSIZE` > /dev/null 2>&1
        echo "Creating disk image..."
        hdiutil create -size 3g -fs HFS+J -volname Cache /Volumes/RamDisk/Cache.dmg

        if [ -d "$CACHELOCATION/Cache" ]
            then
                rm -rf "@CACHELOCATION/Cache"
        fi

        echo "Mounting Cache disk image..."   
        hdiutil attach /Volumes/RamDisk/Cache.dmg -mountpoint "$CACHELOCATION/Cache"
        echo "Completed... exiting..."
fi

After screwing around for an hour or so, I made this, and it does work. Now if I could only hide the Cache volume it shows on the desktop. :D

I still have to fiddle with the disk size to fill the RamDrive.. filesystem overhead, etc.

Still bizzare Edge didn't like the symlink.
 
I'm glad it's working (mostly).

I was trying to recall how to prevent a volume from appearing on the desktop, and I remembered the magic word is "nobrowse". See the man page for 'mount', and then look at the option -nobrowse in hdiutil's man page. (I hope that option is still present. I'm not running Big Sur, so -nobrowse might be one with the dust of history.)

You could report Edge's symlink bug to MS. I recommend briefly describing the whole scenario (RAM-disk etc.), so they understand why working correctly with symlinks would be useful.
 
I already submitted via the Edge feedback tool with what I was doing and why. Hopefully it makes its way to the powers that be.

I'll look into the nobrowse option, thanks!
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.