I have a function that resides on each of our nodes. The function requires access to a folder path for accessing files (not a database). Currently, I synchronize the folders on each of the nodes so that we avoid accessing a single shared drive. Can I avoid this synchronization step and utilize App Fabric caching on a folder? Or is the caching only utilized for formal database queries? Any help would be appreciated.
Share
You can cache any kind of object in AppFabric, as long as it’s serialisable (or serializable if you’re in the US 🙂 ) (which I assume is so it can be marshalled between servers correctly). So you could put all the files in a folder into an AppFabric cache, if you cache each file as an array of bytes.
Just because you can, however, doesn’t mean that you should. You haven’t said whether you’re just reading from, or also writing to, these files; if you’re just reading, on the first read your code would get the byte array from the cache, deserialise it out to disk, and then read it, but on subsequent reads why would you bother getting the cached version again? If you’re writing as well, to update the file you’d again get the cached data, put it back onto disk as a file, update the file, then re-serialise it to update the cache and in a distributed environment like this I’d be concerned about how much time that would take and whether other servers would be making concurrent updates to the same data. You can get round that by introducing AppFabrics pessimistic concurrency, of course, but you’d have to determine for yourself whether the benefits outweigh the potential impact this might have.
You’d also probably still need the set of files on each node, or the shared folder you’re trying to avoid relying on, so that the first node that populates the cache actually has the data to populate it with!
I think I’d look at something like folder replication first for keeping the nodes in sync, ahead of AppFabric caching.